Hi,
I realized a parent/child relationship with following:
Code:
<class name="com.wish.network_mgr.gdwPersistence.data.mainData.TopoLink" table="TOPO_LINK" schema="GDW2">
...
<map name="topoLinkTerminations" cascade="all" inverse="true" fetch="join">
<key>
<column name="TOPO_LINK_CODE" precision="38" scale="0"
not-null="true" />
</key>
<composite-map-key class="com.wish.network_mgr.gdwPersistence.data.mainData.CMapKeyForTopoLinkTerm">
<key-property name="propName" column="PROP_NAME"></key-property>
<key-property name="AZType" column="A_Z_TYPE"></key-property>
</composite-map-key>
<one-to-many
class="com.wish.network_mgr.gdwPersistence.data.mainData.TopoLinkTermination" />
</map>
</class>
In my program, I do the following:
Code:
1)create TopoLink instance(topoLink);
2)create TopoLinkTermination instance(topoLinkTermination);
3) topoLinkTermination.setTopoLink(topoLink);
topoLink.getTopoLinkTerminations().put(
new CMapKeyForTopoLinkTerm(topoLinkTermination.getId().getPropName(),
topoLinkTermination.getId().getAZType()),
topoLinkTermination);
4) save topoLink within a transaction.
When I run the program, the console prints following:
Code:
Hibernate:
/* insert com.wish.network_mgr.gdwPersistence.data.mainData.TopoLink
*/ insert
into
GDW2.TOPO_LINK
(NET_CODE, TOPO_LINK_ID, USER_LABEL, NATIVE_NAME, OWNER, DIRECTION, TOPO_LINK_RATE, ADDITIONAL_INFO, TOPO_LINK_CODE)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate:
/* insert com.wish.network_mgr.gdwPersistence.data.mainData.TopoLinkTermination
*/ insert
into
GDW2.TOPO_LINK_TERMINATION
(PROP_VALUE, TOPO_LINK_CODE, PROP_NAME, A_Z_TYPE)
values
(?, ?, ?, ?)
13:46:49,479 WARN JDBCExceptionReporter:71 - SQL Error: 2291, SQLState: 23000
13:46:49,539 ERROR JDBCExceptionReporter:72 - ORA-02291: integrity constraint (GDW2.SYS_C007614) violated - parent key not found
But what strange is: when save the topoLink object first in a transaction,and then save topoLinkTermination in an another transaction as following:
Code:
1)create TopoLink instance(topoLink);
2) save topoLink;
3)create TopoLinkTermination instance(topoLinkTermination);
4) topoLinkTermination.setTopoLink(topoLink);
topoLink.getTopoLinkTerminations().put(
new CMapKeyForTopoLinkTerm(topoLinkTermination.getId().getPropName(),
topoLinkTermination.getId().getAZType()),
topoLinkTermination);
5) save topoLinkTermination.
It goes well.
Could anyone tell me why first program is wrong?
Thanks.