-->
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: many-to-one errors
PostPosted: Wed May 17, 2006 8:14 am 
Newbie

Joined: Wed May 17, 2006 8:06 am
Posts: 2
Hi

I'm having real problems with a many-to-one mapping. I'm clearly missing something but just can't spot it. Here're my mappings:

<hibernate-mapping>
<class name="Policy" table="policy" >
<id name="id" column="pol_id" type="int" unsaved-value="0" >
<generator class="native"/>
</id>
<property name="dateentered" column="pol_dateentered"/>
<property name="startdate" column="pol_startdate"/>
<property name="mmref" column="pol_mmref"/>
<property name="extref" column="pol_extref"/>
<property name="extref2" column="pol_extref2"/>
<property name="term" column="pol_term"/>
<many-to-one name="user" column="pol_use_id" cascade="save-update"
class="User"/>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="User" table="user">
<id name="id" column="use_id" type="int" unsaved-value="0">
<generator class="native"/>
</id>
<property name="username" column="use_username"/>
<property name="password" column="use_password"/>
<property name="forename" column="use_forename"/>
<property name="surname" column="use_surname"/>
</class>
</hibernate-mapping>

If run seperate tests for saving my User and saving Policy (without the user reference) and they run fine.

When I introduce the many-to-one user element I get the following error:

Hibernate operation: could not insert: [Policy]; SQL []; Column 'POL_USE_ID' cannot be null; nested exception is com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'POL_USE_ID' cannot be null


I'm doing something like this to populate and save my data:

policy = new Policy();
policy.setUser(new User());
policy.setMmref("XYZ123456");
dao.savePolicy(policy);

and it's the last line that's failing.

Any help is really appreciated.

Best

DF


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 9:00 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
<hibernate-mapping>
<class name="Policy" table="policy" >
<id name="id" column="pol_id" type="int" unsaved-value="0" >
<generator class="native"/>
</id>
<property name="dateentered" column="pol_dateentered"/>
<property name="startdate" column="pol_startdate"/>
<property name="mmref" column="pol_mmref"/>
<property name="extref" column="pol_extref"/>
<property name="extref2" column="pol_extref2"/>
<property name="term" column="pol_term"/>
<property name="polUseId" column="pol_use_id"/>
<many-to-one name="user" column="pol_use_id" cascade="save-update" class="User" insert="false" update="false"/>
</class>
</hibernate-mapping>


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.