Hello all!
I'm using Hibernate with MySql DB server, which maintains tables in InnoDB mode, i.e transaction support is on.
I have two object with parent-child relationship: Model and Entity.
Here are fragments of Model.hbm.xml:
Code:
...
<id column="MODEL_ID" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
...
<bag name="entities" inverse="false" lazy="false" cascade="all">
<meta attribute="use-in-tostring">true</meta>
<key column="MODEL_ID"/>
<one-to-many class="com.XXXXX.Entity"/>
</bag>
Here are fragments of Entity.hbm.xml:
Code:
...
<id column="ENTITY_ID" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
...
<property column="MODEL_ID" length="11" name="modelId" not-null="false" type="java.lang.Long">
<meta attribute="use-in-tostring">true</meta>
</property>
So, Model can have a number of Entities-children.
Problem is following. I begin transaction like that:
Code:
Session session = null;
Transaction tx = null;
try {
session = manager.obtainSession();
tx = session.beginTransaction();
than pass newly created Model object with collection of Entities to create method. After it I use session.load(classname, ID) to receive my Model object back. I expect all auto-generated ID fields to be set by proper values. But effect is partial - all ID fields are really set to proper values - either in Model(parent) or in Entitiy(children). BUT! Field modelId in Entity(child) remains NULL, but I expect it to be set to Model Id value.
If I commit session - all became proper (after re-reading from DB using another session). But I need these values inside of initial session! Searching for solution of description of such problem has no success.
Is this a bug, or feature, or maybe I do something wrong?
Thanks in advance for help