Oops! I already found where the auto-xxx settings should be placed, sorry! Anyway I still think you should put all these auto-xxx information together.
Greets, Martin Ivan Levi Universistat Politecnica de Catalunya Centre Tecnologic de Transferencia de Calor On Sat, 2004-05-08 at 03:13, Armin Waibel wrote: > Hi Mark, > > Mark Spritzler wrote: > > > Yes, I think it is backwards myself. > > > > I made the change and the Parent record got inserted. This is my first inserted > > record so far using > OJB, after over two weeks of trying. > > > > wow! Thanks for your patience! Hope we can improve documentation to > prevent user from such pain. > > Using Identity columns is a special case, but nevertheless OJB should be > able to handle this too (and it works, see test case > ...broker.sequence.NativeIdentifierTest in test suite). > > I will try to describe how OJB handles relations. Say we have a base > class A with a 1:1 reference to B and a 1:n reference to C. > > If you set auto-update 'object/true' in the reference- and > collection-descriptor OJB will handle an insert of an A with populated > references automatic > ... > A = new A > A.setB(new B) > List listOfC = getC's > A.setAllCs(listOfC) > broker.store(A) > ... > That's all. > > If you set auto-update 'none/false' you have to do all object insert by > hand and have to set all FK (not possible when anonymous key was used > for 1:1 FK) or better use linking (see > http://db.apache.org/ojb/tutorial3.html#Link%20references) > > Detailed info about the auto-xxx settings can be found in the reference > sections > (e.g. http://db.apache.org/ojb/tutorial3.html#Link%20references) > > To insert objects with references by hand the following order is mandatory: > > First insert all 1:1 referenced objects (insert B) > link A (set FK to B) > Second insert the main object (insert A) > link C's (set FK to A) > Third insert all 1:n collections (insert all C's) > > On delete it's vice versa. > > Hope this information is helpfully. > Any hints how to improve documentation are welcome. > > > regards, > Armin > > > > Unfortunately, the child record never got inserted. > > > > Back after 1 hour. > > > > Here is what I did to make it insert into both tables. Here is my insert method of > > my DAO object > > > > public void insert(ValueObject insertRecord) throws DataAccessException { > > log.info("************Entering the TourDAO.insert***************"); > > PersistenceBroker broker = null; > > try { > > broker = ServiceLocator.getInstance().findBroker(); > > TourVO tour = (TourVO)insertRecord; > > AssumptionVO assumptionVO = tour.getAssumptions(); > > broker.beginTransaction(); > > broker.store(tour); > > assumptionVO.setTour(tour); > > broker.store(assumptionVO); > > broker.commitTransaction(); > > ....... > > > > Of course the other remaining code is just the catch and finally parts. > > > > I thought that OJB was set up that it would have automatically saves the child > > record, instead of me having to call store() a second time on the broker. > > > > But I am happy that I got the records inserted, I can finally move on in my > > project to the next steps. As I had said I have been stuck trying to get OJB to > > work for over two weeks, and this is a simple project I wrote. > > > > Thanks for you help. > > > > Mark > > > > "McCaffrey, John G." <[EMAIL PROTECTED]> wrote: > > > > yes, (my understanding) if you have a 1-1 relationship, but there is a FK > > constraint that indicates a parent > child relationship, then OJB wants the > > Child Mapping to contain a reference to the parent. > > > > I think the basic rule is like this > > mapping for Object A > > contains > > ref to B > > ref to C > > collection ref to D > > > > SQL queries will go like this > > insert B > > insert C > > insert A > > insert D > > > > That was a suprise to me, and I wish it wasn't like that. (I have asked if I > > am just not understanding this, but i haven't gotten a response that says I > > am wrong yet) > > > > What I don't like about it is that if you have a 1-1 child relationship you > > have to invert you mapping to make OJB happy, but it might not make sense > > for yuo object > > > > ex (this is what I would like to do): > > company obj mapping (parent) > > contains > > primary manager obj (only one reference and this is truly a child of > > company) > > primary address obj (same deal) > > > > but this would fail because OJB will try to insert the manager and address > > first > > instead I think you have to do this: > > > > Manager > > contains > > a company > > (I don't even know what will happen with the address) > > > > So if I am understanding this, it really makes it hard for you to use > > composite VOs when you have 1-1 parent-child relationships. > > > > any thoughts? (someone please tell me that I am wrong, and that there is a > > better way to do this) > > > > > > > > -----Original Message----- > > From: Mark Spritzler [mailto:[EMAIL PROTECTED] > > Sent: Friday, May 07, 2004 4:21 PM > > To: OJB Users List > > Subject: RE: Child Table insert at same time as Parent and Auto > > generated PK > > > > > > Hi John, thanks. Actually I have already added the sequence manager to the > > jdbc-connection-descriptor, and also the settings for the primary key. > > > > So are you saying that my reference-descriptor in the Parent table needs to > > be removed and instead add it to my child table? If not then, what do you > > mean. :) > > > > Thanks > > > > Mark > > > > "McCaffrey, John G." wrote: > > Search the archives for SequenceManger and Idenity threads. > > > > Here is what I needed to do: > > add a sequence manager to my jdbc-connection-descriptor > > className="org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl"> > > > > > > Make sure these were set on my primary key > > primarykey="true" > > autoincrement="true" > > access="readonly" > > > > Then I had to flip my mapping because I had > > Parent > contains a reference to a single Child (not a collection) > > but OJB wants Child > contains reference to Parent > > > > HTH > > > > -----Original Message----- > > From: Mark Spritzler [mailto:[EMAIL PROTECTED] > > Sent: Friday, May 07, 2004 4:05 PM > > To: [EMAIL PROTECTED] > > Subject: Child Table insert at same time as Parent and Auto generated PK > > > > > > I am using MySql. > > > > OK. I have a Parent-Child relationship which is 1:1 relationship. I am > > inserting into each table at the same time. Obviously, the Parent gets > > inserted first. But the Primary Key is auto-generated by MySQL in an > > auto-generated field. So when the child record gets inserted, I need that > > newly created ID to be in the child record. But it isn't getting it, and the > > ID in the child is Null, so the Database returns an error for it being Null. > > > > Does anyone know a way to fix this problem? Putting the child fields into > > the Parent table is not a possibility and wouldn't be a good db design > > decision. > > > > Thanks everyone > > > > Mark > > > > > > --------------------------------- > > Do you Yahoo!? > > Win a $20,000 Career Makeover at Yahoo! HotJobs > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > Franziska says, "Keep eating healthy" > > > > she also says that the above line is not actually gramatically correct. > > > > She wants you all to know that healthy cannot be there; it really should be > > an adverb like healthfully. > > > > > > --------------------------------- > > Do you Yahoo!? > > Win a $20,000 Career Makeover at Yahoo! HotJobs > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > --------------------------------- > > Do you Yahoo!? > > Win a $20,000 Career Makeover at Yahoo! HotJobs > > --------------------------------------------------------------------- > 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]