Hi Brain,
----- Original Message -----
From: "Brian Chaplin" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, July 07, 2003 2:44 PM
Subject: Re: How do I customize insert for Sybase identity columns?
> Armin,
> Using SequenceManagerInMemoryImpl didn't work. It looks like the
commands
> issued in the afterInsert callback are on another connection
regardless of
> the memory manager being used.
with the latest version of OJB (more exact version > rc2) the
PersistenceAware callback methods retrieve a
PersistenceBroker instance
e.g.
public void afterInsert(PersistenceBroker broker)
throws PersistenceBrokerException;
with broker.serviceConnectionManager().getConnection()
you will retrieve the current used connection (don't close
the connection after use!! - will be done by OJB, only close
your statement). Then fire your statement.
To isolate your problem, don't use batch-mode
'true' in jdbc-connection-descriptor.
If you don't use CVS please update
ConnectionManagerImpl#setBatchMode(boolean mode)
with
return batchMode && platform.supportsBatchOperations();
or get latest from CVS. This ensure that if batch-mode 'false'
was set, batch mode definitely was not used.
Now try again and post your stack trace ;-)
regards,
Armin
>
> Should I modify the source code somewhere in this stack trace?
>
> at
>
org.apache.ojb.broker.util.batch.BatchConnection.executeBatch(BatchConne
ctio
> n.java:298)
>
> at
>
org.apache.ojb.broker.util.batch.BatchConnection.commit(BatchConnection.
java
> :335)
>
> at
>
org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.localCommit(Conn
ecti
> onManagerImpl.java:200)
>
> at
>
org.apache.ojb.broker.core.PersistenceBrokerImpl.commitTransaction(Persi
sten
> ceBrokerImpl.java:385)
>
> at
>
org.apache.ojb.broker.core.DelegatingPersistenceBroker.commitTransaction
(Del
> egatingPersistenceBroker.java:120)
>
>
> "Armin Waibel" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hi Brain,
> >
> > use another SM implementation (e.g. SequenceManagerInMemoryImpl)
> > or implement your own SequenceManager.
> >
> > HiLo-SM implementation use intern a new connection (because
> > we want to avoid 'rollback trouble'), thus your setting is made
> > on the wrong connection.
> >
> > regards,
> > Armin
> >
> > ----- Original Message -----
> > From: "Brian Chaplin" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, July 03, 2003 8:17 PM
> > Subject: How do I customize insert for Sybase identity columns?
> >
> >
> > > I'm trying to handle sybase and SQL Server identity columns by
> > allowing OJB
> > > to control the sequence number generation through the
> > > SequenceManagerHighLowImpl.
> > >
> > > However, to do this I need to issue a "set identity_insert
tablename
> > on"
> > > before the actual insert statement is executed?
> > >
> > > I did this in the afterInsert method of my BrokerAware persistence
> > object as
> > > follows:
> > >
> > > Connection conn = getConnection();
> > >
> > > stmt = conn.createStatement();
> > >
> > > stmt.execute("set identity_insert mcsp_test on");
> > >
> > > stmt.close();
> > >
> > >
> > >
> > > Although the set statment was executed successfully, when the
> > persistence
> > > broker issued the insert command, it still failed.
> > >
> > > afterInsert
> > >
> > > 1057255340516|0|1|statement||set identity_insert mcsp_test on
> > >
> > > 1057255340516|0|0|batch|INSERT INTO mcsp_test (id,col1) VALUES
(?,?)
> > |INSERT
> > > INTO mcsp_test (id,col1) VALUES ('97','a13')
> > >
> > > 1057255340531|15|0|statement|INSERT INTO mcsp_test (id,col1)
VALUES
> > (?,?)
> > > |INSERT INTO mcsp_test (id,col1) VALUES ('97','a13')
> > >
> > > [org.apache.ojb.broker.accesslayer.ConnectionManagerImpl] ERROR:
> > Commit on
> > > underlying connection failed, try to rollback
> > >
> > > JZ0BE: BatchUpdateException: Error occurred while executing batch
> > statement:
> > > Explicit value specified for identity field in table 'mcsp_test'
when
> > > IDENTITY_INSERT is set to OFF.
> > >
> > >
> > >
> > >
> > >
> > > I'm not sure why. Perhaps it was issued on another connection in
my
> > pool
> > > but this still fails even for a singleton connection.
> > >
> > > Is there a way I can override how the persistence broker is
> > implementing the
> > > insert statement?
> > >
> > > Or is there a way I can customize the insert statement to issue a
"set
> > > command"?
> > >
> > >
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> > >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]