-->
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.  [ 7 posts ] 
Author Message
 Post subject: Parent/Children insertion issue
PostPosted: Fri Aug 27, 2004 11:09 am 
Newbie

Joined: Fri Aug 27, 2004 10:36 am
Posts: 8
I have Parent Class P and a Child Class C(one-to-many), I set cascade="all", when I tried to insert P, the output SQL statements: "insert into P..." and "update C..." instead of "insert into C...", what problems with my mappings?

(There is no problem for deletion)

Thanks in advance.

Parent mapping:
<set
name="c"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="C_Column" />
</key>
<one-to-many
class="C"
/>
</set>

Child Mapping:
<one-to-one
name="p"
class="P"
outer-join="auto"
constrained="true"
cascade="all"
/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 11:27 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
Quote:
inverse="true"


change that to false, and have a look at the hibernate docs to see what the implications of inverse is.

no idea hwy it would work for deletion though, especially since you said cascade="all" and not orphan, anyway try that


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:56 pm 
Newbie

Joined: Fri Aug 27, 2004 10:36 am
Posts: 8
I changed inverse="false", the output is the same. From my understanding, the deletion is working since cascade="all" has the same effect as cascade="delete" from the deletion point view. ("all" covers "delete"). If I changed cascade="save-update", the deletion will fail.

I have no clue that hibernate generate UPDATE statement on child objects/tables instead of INSERT statement which is supposed to. Anybody help?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 7:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why do you have a <one-to-one>, instead of a <one-to-many>?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 9:57 am 
Newbie

Joined: Fri Aug 27, 2004 10:36 am
Posts: 8
Sorry, it is many-to-one, not one-to-one. The child mapping(which has issues) is:

<many-to-one
name="p"
class="P"
update="false"
insert="false"
>
<column name="ID_Column" />
</many-to-one>

if I changed insert='true", I got the following error:

net.sf.hibernate.MappingException: Repeated column in mapping for class C should be mapped with insert="false" update="false": ID_Column
at net.sf.hibernate.persister.AbstractEntityPersister.checkColumnDuplication(AbstractEntityPersister.java:1009)

I guess it is due to the fact that ID_Column is the primary key for P class/table also.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 10:30 am 
Regular
Regular

Joined: Thu Aug 05, 2004 2:27 am
Posts: 54
Location: South Africa
d0yao wrote:
if I changed insert='true", I got the following error:

net.sf.hibernate.MappingException: Repeated column in mapping for class C should be mapped with insert="false" update="false": ID_Column
at net.sf.hibernate.persister.AbstractEntityPersister.checkColumnDuplication(AbstractEntityPersister.java:1009)

I guess it is due to the fact that ID_Column is the primary key for P class/table also.


can you post the complete mapping for the child?

Quote:
From my understanding, the deletion is working since cascade="all" has the same effect as cascade="delete" from the deletion point view. ("all" covers "delete"). If I changed cascade="save-update", the deletion will fail.


hmmm, I thought you meant the row was actually deleted, and didn't just have it's parent key set to null, making it an orphan, which is why "all-delete-orphan" is used.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 11:44 am 
Newbie

Joined: Fri Aug 27, 2004 10:36 am
Posts: 8
(not sure the composite key in Child table will cause any issue)
Parent mapping:

<class
name="package.P"
table="Parent_Table"
>

<id
name="ID"
type="java.math.BigDecimal"
column="ID_Column"
>
<generator class="assigned" />
</id>
<!-- bi-directional one-to-many association to Child -->
<set
name="c"
lazy="false"
inverse="true"
cascade="all"
>
<key>
<column name="ID_Column" />
</key>
<one-to-many
class="package.C"
/>
</set>


Child mapping:

<class
name="package.C"
table="Child_Table"
>
<composite-id name="comp_id" class="package.C_PK">
<key-property
name="id"
column="ID_Column"
type="java.math.BigDecimal"
length="21"
/>
<key-property
name="age"
column="AGE_Column"
type="java.lang.Integer"
length="4"
/>
</composite-id>

<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- bi-directional many-to-one association to Ir -->
<many-to-one
name="p"
class="package.P"
update="false"
insert="false"
>
<column name="ID_Column" />
</many-to-one>
</class>


if I set cascade="all", it really delete all children and parent from Database.


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

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.