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.