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]



Reply via email to