-->
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: foreign key null causing insert to fail
PostPosted: Thu Oct 15, 2009 9:43 am 
Newbie

Joined: Tue Sep 09, 2008 12:07 pm
Posts: 3
I have two tables, base and child, both with numeric synthetic keys created via autoincrement; child table able has foreign key back to base . Tables hibernate mapping is below

Code:
<?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="child" table="child">
      <id name="id" column="id" >
         <generator class="identity">
         </generator>
      </id>
      <property name="baseId" column="baseid" />      
...
      
      <many-to-one  name="base" lazy="false" class="base" cascade="all"   insert="false" update="false">
         <column name="baseId" not-null="true"/>
      </many-to-one>

</class>
</hibernate-mapping>



When I attempt an insert via saveOrUpdate Hibernate correctly issues an insert of base, but then apparently fails to copy the primary key of base to child's baseId field and the second insert errors out with a message indicating that child's baseId cannot be null.

Oct 15, 2009 9:00:10 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1048, SQLState: 23000
Oct 15, 2009 9:00:10 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Column 'baseid' cannot be null


Any insights would be very welcome.


Last edited by saltcreek on Thu Oct 15, 2009 12:31 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: foreign key null causing insert to fail
PostPosted: Thu Oct 15, 2009 10:22 am 
Newbie

Joined: Tue Sep 09, 2008 12:07 pm
Posts: 3
Noticed during posting that my code was referring to the VO property (baseId) rather than the table column (baseid). Thought this might be the problem, but after changing from baseId -> baseid I saw NO change in the behavior.


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.