If I have a mapping of Obj A contains one Obj B and a collection of Obj C
how do I tell ojb to insert table A before tables B or C? I have foriegn key constraints that say A must exist before B can be inserted, and A must exist before C can be inserted. (and the deletes need to happen in the reverse order) This must be very common for everyone, is there a trick to telling it what order the inserts need to go? -----Original Message----- From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 24, 2004 7:19 PM To: OJB Users List Subject: Re: sequence manager help (order of inserts to avoid FK problems) McCaffrey, John G. wrote: > I am using rc 4. i can't get to CVS because I am behind a firewall (and my > manager only wants us to use the labled builds) > > I tried your suggestion to set the > primarykey=true, autoincrement="false" and access="readonly" > for my key (EVNT_RQST_ID) > > and got the exception > Assignment of a NULL value to a NOT NULL column "EVNT_RQST_ID" is not > allowed. > > do you think that upgrading to rc 5 would help? As I can remember there was a bug with autoincrement="false" handling, but I don't know when it was fixed. Give rc5 a change ;-) We plan to release a new version end of this month (and final release one week later - if no major problem arise). > Is there any other way I can tell OJB not to try to autoincrement the keys? > Sorry, only possibility is to fix this in rc4 source code. See BrokerHelper#getValuesForObject > I appreciate your help on this, I see that you are getting a thousand emails > right now, and somehow you manage to answer them. Thanks!! > I try to confuse people with my "exceptional bad" english, nevertheless some people post again and again ;-) regards, Armin > -----Original Message----- > From: Armin Waibel [mailto:[EMAIL PROTECTED] > Sent: Wednesday, March 24, 2004 6:39 PM > To: OJB Users List > Subject: Re: sequence manager help (order of inserts to avoid FK > problems) > > > 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] > > --------------------------------------------------------------------- > 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]