Hi,
I have a Region and associated Regiontext which has PK of (regionid, locale).
In Region.hbm.xml, I have following mapping:
<set name="regiontextsForRegionid" inverse="true" cascade="save-update">
<key column="REGIONID" not-null="true" />
<one-to-many class="test.hib.Regiontext" />
</set>
client side creates a Region object associated with Regiontext objects and passes this Region object tree to session.save().
However, I got exception saying regionId used by Regiontext PK is not there - sounds like Region record is not inserted before Regiontext - which I thought should have been taken care of by the not-null="true" in the <key> element.
I am using Hiberate 3.1 with Oracle 9.1
The exception stack trace reads:
Exception in thread "main" org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Could not execute JDBC batch update; SQL [insert into REGIONTEXT (CURRENTPARENTREGIONID, NAME, REGIONID, LOCALE) values (?, ?, ?, ?)]; ORA-02291: integrity constraint (SCOTT.SYS_C002887) violated - parent key not found
; nested exception is java.sql.BatchUpdateException: ORA-02291: integrity constraint (SCOTT.SYS_C002887) violated - parent key not found
java.sql.BatchUpdateException: ORA-02291: integrity constraint (SCOTT.SYS_C002887) violated - parent key not found
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:612)
at test.dao.RegionDAO.create(RegionDAO.java:18)
where constraint (SCOTT.SYS_C002887) is FK constraint about regionid on Regiontext.
Can someone advise what should I change?
Thx in advance
Chuck
|