-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Cascade save for objects
PostPosted: Thu Feb 24, 2005 8:54 am 
Newbie

Joined: Thu Feb 24, 2005 8:49 am
Posts: 6
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:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.