-->
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: Nested Collections
PostPosted: Tue May 31, 2005 7:33 am 
Newbie

Joined: Wed Mar 23, 2005 4:29 am
Posts: 7
I have 4 classes:
Code:
public class Base{
  ... other attributes...
  X xClass;
}
public class X{
   Map yValues;
}
public class Y{
   String simpleString;
   List zValues;
}
public class Z{
   List strings;
}

The list of the last class contains a FifthClass that has only a string as attribute. My goal is to just say save(instanceOfBase); and be ready.

To do this I have the following mapping:
Code:
<class name="Base" table="model">
   ...
   <many-to-one name="xClass" class="X"cascade="all"/>
</class>


<class name="model.Kalender" table="kalender">
  <id name="id" type="long" unsaved-value="-1">
     <generator class="native"/>
  </id>
  <map name="yValues" cascade="all">
       <key column="yIndex"/>
       <map-key column="yKey" type="date"/>
       <many-to-many class="Y"/>
   </map>
</class>

<class name="Y">
  <id name="id" type="long" unsaved-value="-1">
     <generator class="native"/>
  </id>
  <property name="simpleString" type="string"/>
  <list name="zValues" cascade="all">
      <key column="id"/>
      <list-index column="index"/>
      <one-to-many class="Z"/>
  </list>   
</class>

<class name="Z">
  <id name="id" type="long" unsaved-value="-1">
     <generator class="native"/>
  </id>
   <list name="strings">
      <key column="id"/>
      <index column="index"/>
      <composite-element class="FifthClass">
         <property name="aString" type="string"/>
      </composite-element>
    </list>
</class>


The problem I have is when Hibernate tries to save an object of class Y there is a foreign key constraint on class X
Code:
Integrity constraint violation - no parent FK1838A41684912 table: KALENDER in statement [insert into dag (dagboek, id) values (?, null)]


I assume this has something to do with the complicated nested collections. Does anyone know how to solve this?

Class Y isn't needed anywhere else in my application so if it is usefull I can make some kind of composite element of it.

Thanks for looking at this (quite large) problem!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 10:31 am 
Newbie

Joined: Tue May 31, 2005 8:48 am
Posts: 11
Location: Blumenau - Santa Catarina - Brasil
try add an object of Z in collection of class Y,
i think when you save entity Y, how exist link one-to-many to entity Y,
record of Y not accept field null (field usage to link entity Z).


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 10:44 am 
Newbie

Joined: Wed Mar 23, 2005 4:29 am
Posts: 7
subzero wrote:
try add an object of Z in collection of class Y,
i think when you save entity Y, how exist link one-to-many to entity Y,
record of Y not accept field null (field usage to link entity Z).


I'm afraid I don't quite understand what you are saying.
Do I have to set the key in the Y class to not-null=false or in the Z class or something else?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 1:00 pm 
Newbie

Joined: Tue May 31, 2005 8:48 am
Posts: 11
Location: Blumenau - Santa Catarina - Brasil
try set cascade="none" in class Y, and view result.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 5:39 am 
Newbie

Joined: Wed Mar 23, 2005 4:29 am
Posts: 7
Thanks for the help but I keep getting the same error.
The log4j says before the error
Code:
Hibernate: insert into table_of_z (naam, id) values (?, null)
WARN  - SQL Error: -177, SQLState: 23000
ERROR - Integrity constraint violation - no parent FKAA91B8D788164040 table: Y in statement [insert into table_of_z (naam, id) values (?, null)]

I think the problem is the null in id, but how can i fix it?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 10:29 pm 
Newbie

Joined: Fri Jun 17, 2005 4:35 pm
Posts: 3
Hi, did you solve this? I have the same problem....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 10:58 am 
Newbie

Joined: Tue May 31, 2005 8:48 am
Posts: 11
Location: Blumenau - Santa Catarina - Brasil
value of property ID is null, alter type of your primary key field to auto_increment.


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.