Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1
how does hibernate handle inserting an object tree where the top-level object has an assigned key (assigned in the database with a trigger) and is a foreign key to a child object. if i am explaining this poorly, here's a simple example. i have a class Foo, instances of which contain a set of Bar objects. the mapping for the foo table indicates that it has keys assigned by database triggers
Mapping documents:
Foo.hbm.xml:
Code:
<class name="hello.Foo" table="FOO">
<id name="id" column="FOO_ID">
<generator class="assigned"/>
</id>
...
<set name="bars" inverse="true">
<key>
<column name="FOO_ID" />
</key>
<one-to-many class="hello.Bar"/>
</set>
</class>
Bar.hbm.xml:
Code:
<class name="hello.Bar" table="BAR">
<id name="id" column="BAR_ID">
<generator class="assigned"/>
</id>
...
<many-to-one name="foo" class="hello.Foo">
<column name="FOO_ID" />
</many-to-one>
</class>
in my code i could have something like this:
Code:
Foo foo = new Foo();
session.save(foo);
String fooId = session.getIdentifier(foo);
and i'd be able to see the assigned id. or i could do this:
Code:
Foo foo = new Foo();
session.save(foo);
session.flush();
session.refresh(foo);
and i'd expect to see the newly assigned id in foo.
but if i do this:
Code:
Foo foo = new Foo();
foo.addBar(new Bar()); // add bar to bars
session.save();
does hibernate get the foreign key reference correct here? does it go and get the generated key after persisting foo so it can set the foreign key reference in Bar's backing table correctly?