-->
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.  [ 13 posts ] 
Author Message
 Post subject: Composit Id and the bidirectional assotiaion
PostPosted: Thu Nov 17, 2005 1:06 pm 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
Could you please help me. I'v two clacess:
...
<hibernate-mapping>
<class
name="by.belsoft.tts.core.model.project.ProjectUser"
table="tts_project_user"
lazy="false"
>
<composite-id>

<key-property
name="portalUserId"
column="portal_user_ID"
length="255"
type="java.lang.String"
/>

<key-many-to-one
name="project"
class="by.belsoft.tts.core.model.project.Project"
column="project_ID"
/>
</composite-id>
</class>
</hibernate-mapping>

and:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<class
name="by.belsoft.tts.core.model.project.Project"
table="tts_project"
lazy="false"
>
<id
name="projectId"
type="java.lang.Integer"
column="project_ID"
>
<generator class="increment" />
</id>
<!--
... properties
-->
<set
name="projectUsers"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
>
<key
on-delete="cascade"
not-null="true"
column="project_ID"
/>
<one-to-many
class="by.belsoft.tts.core.model.project.ProjectUser"/>
</set>
<!--
...
-->

I know about the http://www.hibernate.org/hib_docs/refer ... -onetomany.
And I'v the following proplem:
while I try to update the Project with set of ProjectUsers I have the following:
nested exception is org.springframework.dao.DataIntegrityViolationException: (Hibernate operation: Could not execute JDBC batch update): data integrity violated by SQL 'insert into tts_project_user (portal_user_ID, project_ID) values (?, ?)'; nested exception is java.sql.BatchUpdateException: Column 'portal_user_ID' cannot be null

The equals and hashCode were tested and the ProjectUser class is serializabled.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 3:34 pm 
Newbie

Joined: Fri Oct 28, 2005 10:54 pm
Posts: 12
I have been struggling with a very similar problem. From what I've been able to gather from the reference documentation - for the one-to-many set you have to use inverse=true, which it appears you have. The next piece of the puzzle which it looks like you may be missing is that the you have to have not-null="true" for the many-to-one for the project_id column. Apparently this lets hibernate know how to handle the processing of the 'child' entity in the join table.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 4:53 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
How can I set the atribute not-null="true" in many-to-one association if the association is key-many-to-one? :)
As I see the key is not-null by default. But such association doesn't work. Moreover, the object retriving work properly, but object saving doesn,t.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 6:21 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

I had problems with set How about a bag?

<bag name="projectUsers" lazy="false" inverse="true" cascade="all-delete-orphan" >
<key column="project_ID"></key>
<one-to-many class="by.belsoft.tts.core.model.project.ProjectUser"/>
</bag>

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 6:43 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
Quote:
I had problems with set How about a bag?


What are you speaking about?

In my case the set is the best solution. And I have tested with <bag/> - the issue still same. The pairs in ProjectUser (project_ID and project_user_ID) should be unique.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 5:43 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
Is it really none know about the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 6:52 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
Unfortunately I'm going to realize this http://www.hibernate.org/117.html#A34


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 7:28 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
I have tried the following:
http://www.hibernate.org/117.html#A34
but the result still same. I expect that I have an error in the mapping.
Please, advice.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 2:45 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Reread Chapter 6:
From Chapter 6 wrote:
Very Important Note: If the <key> column of a <one-to-many> association is declared NOT NULL, Hibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse="true". See the discussion of bidirectional associations later in this chapter.

_________________
hth,
Heinz
Don't forget to rate if this helped


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 6:52 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
As you can see:
<set
name="projectUsers"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
>
<key
on-delete="cascade"
not-null="true"
column="project_ID"
/>
<one-to-many
class="by.belsoft.tts.core.model.project.ProjectUser"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 7:21 am 
Regular
Regular

Joined: Sat Nov 05, 2005 5:33 am
Posts: 70
Location: Linz, Austria
Sorry, must have looked with "the white part of the eyes" ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 12:03 pm 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
The problem was described also at:
http://www.guj.com.br/posts/list/32719.java
Unfortunately there is no answer in this forum.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 10:41 am 
Newbie

Joined: Thu Nov 17, 2005 12:59 pm
Posts: 18
I'h solved the problem throught:
http://www.hibernate.org/117.html#A34
and using pure update only. Whithount any preload and merge - this ways don't work.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.