My mappings...
Code:
<hibernate-mapping>
<class name="Task" table="tasks">
<id name="id" column="task_id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" column="task_name" type="string" length="30" not-null="true"/>
<property name="code" column="task_code" type="string" length="30" not-null="true"/>
<property name="expirationDate" column="task_expirationDate" type="java.sql.Date" not-null="true"/>
<set name="taskAttributes" table="taskAttributes" cascade="all" inverse="true" lazy="true">
<key column="task_id"/>
<one-to-many class="TaskAttribute"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="TaskAttribute" table="taskAttributes">
<id name="id" column="taskAttribute_id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="expirationDate" column="taskAttribute_expirationDate" type="java.sql.Date" not-null="true"/>
<many-to-one name="task" class="Task" column="task_id" not-null="true" cascade="all"/>
<one-to-one name="attribute" class="Attribute" column="attribute_id" not-null="true"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="Attribute" table="attributes">
<id name="id" column="attribute_id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" column="attribute_name" type="string" length="30" not-null="true"/>
<property name="expirationDate" column="attribute_expirationDate" type="java.sql.Date" not-null="true"/>
</class>
</hibernate-mapping>
I first create an instance of an Attribute save it to the DB using hibernate, then create an instance of Task and pass the attribute as param, so Task creates a TaskAttribute which keep the reference to the attr and the task.
But when i save the Task using hibernate i get ....
Code:
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:687)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:640)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2361)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at Test.main(Test.java:51)
Exception in thread "main" net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:687)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:640)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2361)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at Test.main(Test.java:51)