Hi again,

did you try latest version from CVS? Latest version of PlatformDb2Impl override method getLastInsertIdentityQuery and return the same query string you use.

If you don't want to use the sequence manager from OJB
primarykey=true, autoincrement="false" and access="readonly" should work (and do work with latest from CVS). What version of OJB do you use?


regards,
Armin

McCaffrey, John G. wrote:
Almost there!
Ok, I just made the changes you suggested, and it is working, kinda.
I insert table A first (because that's where I get my Id from)
I assign the ID from A into B
then I go to insert table B
if I try to tell it that the primarykey=true and autoincrement="false"
(beacause I don't want it to try to get the Identity from the DB for this
table, because it is not an Identity)
I get the exception


 org.apache.ojb.broker.util.sequence.SequenceManagerException: Field does
not support autoincrement, please check repository: null
>
so I set autoincrement="true" (just to see if that would work) and then it
works (Yay!) but I also see that it made the trip to the db to try to get
the Identity (because it thinks there is one for this table) and I would
like to avoid that unecessary trip (if possible).

Why does it get upset that autoincrement="false" ?


p.s. I had to make a custom getLastInsertIdentityQuery() because thats the only way that I could get OJB to call the DB with the statement I need for DB2 SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1 the PlatformDb2Impl doesn't have anything in that method, so I had to extend it and override.





-----Original Message-----
From: Armin Waibel [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 24, 2004 6:02 PM
To: OJB Users List
Subject: Re: sequence manager help (order of inserts to avoid FK
problems)


Hi John,


McCaffrey, John G. wrote:

I have a DB generated Identity column for Table A and I am able to use OJB
to insert that object A and see what the identity is with a custom
getLastInsertIdentityQuery() method. (Yay!)



Why you don't use SequenceManagerNativeImpl?
http://db.apache.org/ojb/sequencemanager.html#nativeSequenceManager


I have a table B that is associated to Table A, but its ID is not

generated.


When I insert into Table A and get the generated ID, I would like to

insert


into table B and use that same ID. in my mapping for Table A I have a reference descriptor to Table B, with
auto-XXX all true




You can't use auto-udate true in your case, because OJB needs the PK of B to set the FK in A before storing A (assume you declared an 1:1 reference between A and B).
The SequenceManager interface contains two methods only for handle DB identity based key generation:
setReferenceFKs(Object obj, ClassDescriptor cld)
afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object



If I try to insert Obj A that has an Obj B inside of it, it appears that

OJB


tries to insert Obj B first. This will fail because the ID has not been
generated yet.

How can I get OJB to insert Obj A first, then assign that ID to Obj B ?



Think with your current solution it is only possible if you store all objects by hand and set auto-update false. Store B first then set FK in A and store A.

regards,
Armin


---------------------------------------------------------------------
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]



Reply via email to