-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem persisting collections
PostPosted: Mon May 10, 2004 4:41 pm 
Beginner
Beginner

Joined: Wed Sep 03, 2003 9:31 am
Posts: 26
Hi fellows. I'm facing a problem with collections.

I got two collections, addresses of PersonAddress, and contactMeans of PersonContactMean, in a class called Person.

First, I had only contactMeans in Person, and when I tried to saveOrUpdate a new instance of Person that had one or more contactMeans everything was ok.

But after I created addresses field, same way I did with contactMeans, I started to get "ERROR: null value in column person_id violates not-null constraint" when I try to save it.

And it's true: I didn't assign person's id to a new PersonAddress I created. But I didn't do it to PersonContactMean too, and this last was working fine.


What am I doing wrong here?

I'm using hibernate 2.1.3 with PostgreSQL 7.4.1. Here's my mappings:

Code:
<hibernate-mapping>
   <class name="eg.beans.Person" proxy="eg.beans.Person" discriminator-value="person" table="person">
      .
      .
      .
      my properties
      .
      .
      .
      
      <set name="contactMeans" cascade="all" lazy="true" table="contact_mean">
         <key column="person_id"/>
         <one-to-many class="eg.beans.PersonContactMean"/>
      </set>
      
      <set name="addresses" cascade="all" lazy="true" table="person_address">
         <key column="person_id"/>
         <one-to-many class="eg.beans.PersonAddress"/>
      </set>
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="eg.beans.PersonAddress" table="person_address">
      .
      .
      .
      my properties
      .
      .
      .
      <many-to-one name="person" class="eg.beans.Person" column="person_id" insert="false" update="false"/>
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="eg.beans.PersonContactMean" table="person_contact_mean">
      .
      .
      .
      my properties
      .
      .
      .
      <many-to-one name="person" class="eg.beans.Person" column="person_id" insert="false" update="false"/>
   </class>
</hibernate-mapping>


And here's my code:
Code:
if (person.getAddresses().isEmpty()) {
   pa = new PersonAddress();
   pa.setPersonId(id);
   pa.setAddressTypeId(new Integer(1));
   pa.setPerson(person);
   person.getAddresses().add(pa);
} else {
   pa = (PersonAddress)person.getAddresses().iterator().next();
}
.
.
.
fill PersonAddress with form's values
session.saveOrUpdate(person);
JDBCException occurs
.
.
.


Thanx in advance for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 12:33 pm 
Beginner
Beginner

Joined: Wed Sep 03, 2003 9:31 am
Posts: 26
Hey, can someone help me with the above?
Is my problem explanation too confuse?
Please, let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Read the "Parent Child Relationships" chapter in the docs.


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