hal arnold wrote:
I just want to make sure that I'm doing the right thing here, since I've not been able to find a unit test for the simple case of a 1:1 association create. Heres what I had to do to get it working. The navigation is from the child to the parent, one way:
1. create the parent and the child objects, associate the child with the parent: .. parent.setChild(child)
parent has an attribute child too? I thought child only has a reference attribute to its parent?
then 2. 'store' the parent (pb.store(parent)), getting it's id first (getIdentity) so you can put it in the child's parentId ref., and then set the child's parentId.
that's not necessary, OJB handles foreign keys transparently.
THEN, (I hope this is right), I had to:
3. pb.retrieveReference(child, "parent");
I don't understand this step. If you have a one way navigation from parent to child you simply use
parent.setChild(child);
if you have one way navigation from child to parent you call
child.setParent(parent);
if you have bidirectional navigation you call both setters.
4. 'store' the child..
If you setup auto-update="true" on the reference-descriptor you only have to store the parent and the child is inserted automatically.
This actually works, but seems a little complicated. It seems to me that I should be able to create the model associations and just say 'store' on the parent, no?
sure! have a look at the testcases for automatic handling of foreign keys. things can ve much easier!
cheers, Thomas
Is this even right? I got the retrieveReference from looking at a number of the tests, but none that specifically address the simple case of 1:1.
as for the repository, the only thing interesting is that the child has:
<reference-descriptor name="parent" class-ref="com.xx.ormap.test.Parent" auto-update="true" > <foreignkey field-ref="parentId"/> </reference-descriptor>
Thanx
-hba
__________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
--------------------------------------------------------------------- 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]
