That's basically how it works. We have triggers which upon insert will populate the "autonumber" fields. The triggers didn't look to see if the autonumber was already populated so if I had used the sequence based implementation I'd have ended up incrementing the sequence twice and none of my fk's would have the proper information in them. This would probably cause integrity constraint violations, but we've since changed the triggers to detect if the autonumber is populated. The dba isn't completely happy with this solution (ojb gets the sequence numbers and populates, anything else doesn't), but he's ok with it. The "normal" route for records is to be inserted for the master record with a stored procedure, but the "child" tables are all direct inserts with triggers to take care of things.
sounds complex, the only alternative I know is to implement your own SequenceManager:
public Object getUniqueValue(FieldDescriptor field)
this method was called by OJB to obtain a new sequence key *before* the object is inserted. In your case return a dummy value, see SequenceManagerNativeImpl implementation (e.g. return a negative count number)
public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj)
this method was called after the insert statement was executed. Here you can start working and e.g. call a stored procedure to lookup the sequence key and set the PK field in the object, see SequenceManagerNativeImpl implementation.
public void setReferenceFKs(Object obj, ClassDescriptor cld) was no longer used in OJB, make a noop.
Don't know if this will help you, but a bird in the hand is worth two in the bush ;-)
regards, Armin
--mikej -=----- mike jackson [EMAIL PROTECTED]
-----Original Message-----
From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Friday, April 15, 2005 3:42 PM
To: OJB Users List
Subject: Re: Sequence managers and insert triggers
Hi Mike,
think I don't understand your problem (never used insert trigger), so be patience. If you are using a insert trigger I assume the trigger set the PK value on insert of new objects? Or do you using a stored procedure to get the key or to insert the whole object?
OJB supports database generated sequences. A sequence manager supporting this kind of key generation can be found here: http://db.apache.org/ojb/docu/guides/sequencemanager.html#Data
base+sequences+based+implementation
The SequenceManagerNativeImpl supports database identity columns, don't know if Oracle supports this (the exception indicate it doesn't).
regards, Armin
Mike Jackson wrote:
Actually I take it back, I was getting a -2, but when I got the attributes on the identity column set properly I'm getting a
"java.lang.UnsupportedOperationException: This feature is not supported by this implementation". Perhaps this is the
wrong sequence
manager to use on oracle?
--mikej -=----- mike jackson [EMAIL PROTECTED]
-----Original Message----- From: Mike Jackson [mailto:[EMAIL PROTECTED] Sent: Friday, April 15, 2005 2:45 PM To: 'OJB Users List' Subject: Sequence managers and insert triggers
I'm running on an Oracle database (8i) with insert triggers
to create artifical keys for my table records. The howtos seemed to indicate that SequenceManagerNativeImpl might be the proper sequence manager to use but the keys are coming out goofy, so clearly I'm not understanding or something. Which of the sequence managers should I be using? I've got other applications using the same database, so removing the triggers and using the native sequences via OJB isn't an option at this time.
--mikej -=----- mike jackson [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]
--------------------------------------------------------------------- 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]
