I got a intersting question related to cascaded persistence of objects:
I got two classes, Class Org and Class Dept.
Code:
public Class Org{
private int orgID;
private int govID;
private String orgName;
private Set depts;
}
public Class Dept{
private DeptPK deptId;
private int attributeB1;
private String attributeB1;
}
public DeptPK{
private int orgID;
private int someOtherExistingObjPK;
}
Class Org to Class Dept is one to many association and Dept is treated as child object of Org
but it is not mapped as component so that other modules can use this class Dept.
When I am creating Org, I am creating a collection of Dept objects as well.
The objective is save the collection of Dept along with object Org when object Org is saved.
I am populating class Org wihout primary key ID, and I am populating
Class Dept without its primary key, which is a composite ID(DeptPK)
And when I am saving, it is giving differnt error based on differnt mapping is used:
Below are some sample errors I encountered, I would highly apprciate any help regarding this mapping
issue:
1. When I am using DeptPK is left null
Code:
<set name="bObject" table="bObjectTableName">
<key column="keyColumn"/>
<one-to-many class="AClass"/>
</set>
throws exception to save transitive object Dept before saving Org
2. When I am using DeptPK is left null
Code:
<set cascade="All" name="bObject" table="bObjectTableName">
<key column="keyColumn"/>
<one-to-many class="AClass"/>
</set>
Says to create and populate IDs before saving.
3. When I am using DeptPK as filled object without the OrgId
Code:
<set cascade="All" name="bObject" table="bObjectTableName">
<key column="keyColumn"/>
<one-to-many class="AClass"/>
</set>
it says cannot insert null value into the primary key column.
I am wondering, how should I proceed, when I am creating only the Org object and doing the
insert to Dept by using the generated OrgId separly it works, but not cascaded, how should
I go aboout this?
Many Thanks,
Arshad
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: