Robert --
You didn't include any info from your repository file, but based on your description,
it appears that you've got two reference-descriptors defined for the 'bth' class in
your repository file. If that's not true, then disregard everything I'm about to
say...
When you persist an object ("X") that has one or more reference-descriptors associated
with it, OJB will extract the values of the primary keys from the referenced object(s)
and use those extracted values when it persists "X". So in your case, when you
persist the "bth" object, OJB extracts the brokerID from the object that's passed when
you call setBroker(...), and it extracts the homeID from the object that's passed when
you call setHome(...).
In the code snippet that you sent, you could leave out the calls to bth.setBrokerID
and bth.setHomeID and the "bth" object would still be saved successfully.
Ron Gallagher
Atlanta, GA
[EMAIL PROTECTED]
>
> From: "Robert S. Sfeir" <[EMAIL PROTECTED]>
> Date: 2003/02/23 Sun AM 11:34:20 EST
> To: oJB List <[EMAIL PROTECTED]>
> Subject: Can someone please explain why...
>
> Ok So I'm trying to insert a record in a table which has foreignkeys
> defined to 2 tables, and for a while there it kept failing with a
> message saying the transaction could not be committed the lock failed
> for Batch 0.
>
> So I dug my heels in and figured it out, but I don't understand why OJB
> doesn't do this auto:
>
> Tables involved:
> Homes
> homeID
> Collection reference to BrokersToHomes
>
> Brokers
> brokerID
> Collection reference to BrokersToHomes
>
> BrokersToHomes
> recordID (prim key auto increment)
> brokerID
> homeID
> foreignkey reference to Homes homeID
> foreignkey reference to Brokers homeID
>
> When I first tried to insert data in BrokersToHomes it kept failing.
> Then on a hunch, before I did the insert I did:
>
> BrokersToHomes bth = new BrokersToHomes();
> bth.setBroker(broker);//Added this which I already had in memory
> bth.setHome(home);//Added this which comes from selecting a Home
> bth.setBrokerID(broker.getBrokerID());
> bth.setHomeID(home.getHomeID());
>
> Then called the insert which basically submits bth for insert.
>
> That worked.
>
> So my question is:
> Why do I have to set the Broker and Home objects if I am submitting a
> BrokerID and HomeID? Why can't OJB just figure that out for itself?
> I'm using the ODMG API as usual.
>
> While this works, it just seems like overhead for me to have to select
> a Home object and a Broker object then do the insert. I worked around
> it of course by storing the Home object is a session scope so I don't
> have to re select it every time the user wants to insert a new Broker
> relationship.
>
> There also doesn't seem to be any code examples on the site on how to
> do this, and had to guess at it based on previous experiences I had to
> go through when I was doing updates, which also needs to have an object
> selected first, and then updated.
>
> Thanks.
>
> R
>
> P.S. A VERY cool feature is that when you insert a record in any
> table, the primary key if autogenerated gets auto populated to the
> object being inserted... now THAT I really dig.
>
> --
> Robert S. Sfeir
> Senior Java Engineer
> Codepuccino, Inc.
> [EMAIL PROTECTED]
>
> definition - Codepuccino n:
> A Little JSP mixed with lots of Java, usually served with Servlets, a
> Datasource, a sprinkle of XML, and sometimes EJB. (See Great MVC
> Frameworks)
>
>
> ---------------------------------------------------------------------
> 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]