-->
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.  [ 2 posts ] 
Author Message
 Post subject: hibernate inserts null for many-to-one association
PostPosted: Mon Oct 27, 2003 9:17 am 
Newbie

Joined: Thu Sep 25, 2003 11:00 am
Posts: 2
Hi,

I've got a class Actor and a class File. Each file is opened by one Actor, while an Actor can open multiple Files. Here are parts of the mapping files for both classes:

Code:
<class name="Actor" table="actors">
               <id name="id" column="id" type="long">
                    <generator class="sequence">
                            <param>actors_id_seq</param>
                    </generator>
               </id>
               <property name="firstName" column="firstname" type="string" />
               <property name="lastName" column="lastname" type="string" />
</class>


Code:
<class name="File" table="file">
               <id name="id" column="id" type="long">
                    <generator class="sequence">
                            <param>file_id_seq</param>
                    </generator>
               </id>
               <property name="dateClosing" column="date_closing"/>
               <many-to-one name="openedBy" column="opened_by" class="be.arafox.sheria.business.Actor"/>
</class>


I get an Actor object from the DB (PostgreSQL 7.2), using the find-method, and use the method setOpenedBy(Actor actor) to link it to the File object. Now when I save the File object, it says i'm trying to assign null to the column opened_by. It seems there is a problem on the mapping layer, but I have no idea what. Somebody could hive me hint? I'm using Hibernate 1.1.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/116.html#A6
I'm having trouble with a bidirectional association.

When you update a bidirectional association you must update both ends.

parent.getChildren().add(child);
child.setParent(parent);

_________________
Emmanuel


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