-->
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.  [ 1 post ] 
Author Message
 Post subject: how to create master and detail records together?
PostPosted: Mon Apr 17, 2006 12:45 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 9:00 pm
Posts: 37
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.