-->
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: unidirection one-to-many with join table probelm in oracle
PostPosted: Thu Aug 28, 2008 7:23 pm 
Newbie

Joined: Thu Aug 28, 2008 6:52 pm
Posts: 1
I am trying to implement unidirection one-to-many with a join table
I have Hibernate 3.2.6, Oracle 10g, JDK 1.5

tables and the key columns: (PK:Primary Key, FK:Foreign Key)
TM_CAMPAIGN:
CAMP_ID (PK) not null
TM_CAMP_JOINT_EMAIL_BODY:
CAMP_ID (FK) not null, <FK: FK_CAMP_JEMB>
EMBD_ID (FK) not null, <FK: FK_EMBD_JEMB>
TM_CAMP_EMAIL_BODY:
EMBD_ID (PK) not null

mapping file:
<hibernate-mapping>
<class name="pw.CampaignDetail" table="TM_CAMPAIGN">
<id name="campId" type="int" column="CAMP_ID">
<generator class="sequence">
<param name="sequence">CAMP_ID</param>
</generator>
</id>
<set name="campaignEmailBodies" table="TM_CAMP_JOINT_EMAIL_BODY" cascade="all">
<key column="CAMP_ID"/>
<many-to-many column="EMBD_ID" unique="true" class="pw.EmailBody"/>
</set>
</class>
<class name="pw.EmailBody" table="TM_CAMP_EMAIL_BODY" >
<id name="emailBodyId" type="int" column="EMBD_ID">
<generator class="sequence">
<param name="sequence">EMBD_ID</param>
</generator>
</id>
</class>
</hibernate-mapping>

java classes:
CampaignDetail.java
private int campId;
private Set<EmailBody> campaignEmailBodies;
getters, setters

EmailBody.java
private int emailBodyId;
getters, setters

test code:
CampaignDetail campDetail = new CampaignDetail();
EmailBody body1 = new EmailBody();
EmailBody body2 = new EmailBody();
campDetail.getCampaignEmailBodies().add(body1);
campDetail.getCampaignEmailBodies().add(body2);

session.beginTransaction();
session.save(campDetail);
session.getTransaction().commit();

When executed, the correct insert commands were generated, but got
java.sql.BatchUpdateException: ORA-02291: integrity constraint (TMTEST.FK_EMBD_JEMB) violated - parent key not found

I appreciate your help!

Following is the more detail debug log:
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Static SQL for entity: pw.EmailBody
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Version select: select EMBD_ID from
……
[main] DEBUG org.hibernate.transaction.JDBCTransaction - begin
[main] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
[main] DEBUG org.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
[main] DEBUG org.hibernate.connection.DriverManagerConnectionProvider - opening new JDBC connection
……
[main] DEBUG org.hibernate.SQL - select CAMP_ID.nextval from dual
Hibernate: select CAMP_ID.nextval from dual
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: 693
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 693, using strategy: org.hibernate.id.SequenceGenerator
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - saving [pw.CampaignDetail#693]
[main] DEBUG org.hibernate.engine.Cascade - processing cascade ACTION_SAVE_UPDATE for: pw.CampaignDetail
[main] DEBUG org.hibernate.engine.Cascade - done processing cascade ACTION_SAVE_UPDATE for: pw.CampaignDetail
[main] DEBUG org.hibernate.event.def.WrapVisitor - Wrapped collection in role: pw.CampaignDetail.campaignEmailBodies
[main] DEBUG org.hibernate.engine.Cascade - processing cascade ACTION_SAVE_UPDATE for: pw.CampaignDetail
[main] DEBUG org.hibernate.engine.Cascade - cascade ACTION_SAVE_UPDATE for collection: pw.CampaignDetail.campaignEmailBodies
[main] DEBUG org.hibernate.engine.CascadingAction - cascading to saveOrUpdate: pw.EmailBody
[main] DEBUG org.hibernate.engine.IdentifierValue - id unsaved-value: 0
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - transient instance of: pw.EmailBody
[main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - saving transient instance
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[main] DEBUG org.hibernate.SQL - select EMBD_ID.nextval from dual
Hibernate: select EMBD_ID.nextval from dual
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: 461
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 461, using strategy: org.hibernate.id.SequenceGenerator
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - saving [pw.EmailBody#461]
[main] DEBUG org.hibernate.engine.CascadingAction - cascading to saveOrUpdate: pw.EmailBody
[main] DEBUG org.hibernate.engine.IdentifierValue - id unsaved-value: 0
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - transient instance of: pw.EmailBody
[main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - saving transient instance
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[main] DEBUG org.hibernate.SQL - select EMBD_ID.nextval from dual
Hibernate: select EMBD_ID.nextval from dual
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[main] DEBUG org.hibernate.id.SequenceGenerator - Sequence identifier generated: 462
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 462, using strategy: org.hibernate.id.SequenceGenerator
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - saving [pw.EmailBody#462]
[main] DEBUG org.hibernate.engine.Cascade - done cascade ACTION_SAVE_UPDATE for collection: pw.CampaignDetail.campaignEmailBodies
[main] DEBUG org.hibernate.engine.Cascade - done processing cascade ACTION_SAVE_UPDATE for: pw.CampaignDetail
[main] DEBUG org.hibernate.transaction.JDBCTransaction - commit
[main] DEBUG org.hibernate.impl.SessionImpl - automatically flushing session
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - flushing session
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
[main] DEBUG org.hibernate.engine.Cascade - processing cascade ACTION_SAVE_UPDATE for: pw.CampaignDetail
[main] DEBUG org.hibernate.engine.Cascade - cascade ACTION_SAVE_UPDATE for collection: pw.CampaignDetail.campaignEmailBodies
[main] DEBUG org.hibernate.engine.CascadingAction - cascading to saveOrUpdate: pw.EmailBody
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - persistent instance of: pw.EmailBody
[main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - ignoring persistent instance
[main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - object already associated with session: [pw.EmailBody#461]
[main] DEBUG org.hibernate.engine.CascadingAction - cascading to saveOrUpdate: pw.EmailBody
[main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - persistent instance of: pw.EmailBody
[main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - ignoring persistent instance
[main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener - object already associated with session: [pw.EmailBody#462]
[main] DEBUG org.hibernate.engine.Cascade - done cascade ACTION_SAVE_UPDATE for collection: pw.CampaignDetail.campaignEmailBodies
[main] DEBUG org.hibernate.engine.Cascade - done processing cascade ACTION_SAVE_UPDATE for: pw.CampaignDetail
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushing entities and processing referenced collections
[main] DEBUG org.hibernate.engine.Collections - Collection found: [pw.CampaignDetail.campaignEmailBodies#693], was: [<unreferenced>] (initialized)
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Processing unreferenced collections
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Scheduling collection removes/(re)creates/updates
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 3 insertions, 0 updates, 0 deletions to 3 objects
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
[main] DEBUG org.hibernate.pretty.Printer - listing entities:
[main] DEBUG org.hibernate.pretty.Printer - pw.EmailBody{emailBodyId=461, emailContentType=text/html, emailBody=camp2 emailBody is clob - text/html}
[main] DEBUG org.hibernate.pretty.Printer - pw.EmailBody{emailBodyId=462, emailContentType=text/plain, emailBody=camp2 emailBody is clob - text/plain}
[main] DEBUG org.hibernate.pretty.Printer - pw.CampaignDetail{…, campaignEmailBodies=[pw.EmailBody#461, pw.EmailBody#462], …}
[main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - executing flush
[main] DEBUG org.hibernate.jdbc.ConnectionManager - registering flush begin
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Inserting entity: [pw.CampaignDetail#693]
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[main] DEBUG org.hibernate.SQL - insert into TM_CAMPAIGN (CAMP_NAME, CAMP_DESC, CAMP_SQL_CONDITION, CAMP_FROM_EMAIL_ADDRESS, CAMP_FROM_NAME, CHAR_CODE, CAMP_EMAIL_SUBJECT, CAMP_IS_ACTIVE, CAMP_IS_EDITOR, CAMP_IS_SALON_CLIENT, CAMP_IS_WEB_CLIENT, CAMP_IS_COUNTER_CLIENT, CAMP_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) …
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [pw.CampaignDetail#693]
[main] DEBUG org.hibernate.type.StringType - binding 'camp2 camp name' to parameter: 1
……
[main] DEBUG org.hibernate.type.IntegerType - binding '693' to parameter: 13
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Inserting entity: [pw.EmailBody#461]
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
[main] DEBUG org.hibernate.jdbc.Expectations - success of batch update unknown: 0
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[main] DEBUG org.hibernate.SQL - insert into TM_CAMP_EMAIL_BODY (EMBD_CONTENT_TYPE, EMBD_BODY, EMBD_ID) values (?, ?, ?)
Hibernate: insert into TM_CAMP_EMAIL_BODY (EMBD_CONTENT_TYPE, EMBD_BODY, EMBD_ID) values (?, ?, ?)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [pw.EmailBody#461]
[main] DEBUG org.hibernate.type.StringType - binding 'text/html' to parameter: 1
[main] DEBUG org.hibernate.type.StringType - binding 'camp2 emailBody is clob - text/html' to parameter: 2
[main] DEBUG org.hibernate.type.IntegerType - binding '461' to parameter: 3
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Inserting entity: [pw.EmailBody#462]
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - reusing prepared statement
[main] DEBUG org.hibernate.SQL - insert into TM_CAMP_EMAIL_BODY (EMBD_CONTENT_TYPE, EMBD_BODY, EMBD_ID) values (?, ?, ?) …
[main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [pw.EmailBody#462]
[main] DEBUG org.hibernate.type.StringType - binding 'text/plain' to parameter: 1
[main] DEBUG org.hibernate.type.StringType - binding 'camp2 emailBody is clob - text/plain' to parameter: 2
[main] DEBUG org.hibernate.type.IntegerType - binding '462' to parameter: 3
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 2
[main] DEBUG org.hibernate.jdbc.Expectations - success of batch update unknown: 0
[main] DEBUG org.hibernate.jdbc.Expectations - success of batch update unknown: 1
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[main] DEBUG org.hibernate.persister.collection.AbstractCollectionPersister - Inserting collection: [pw.CampaignDetail.campaignEmailBodies#693]
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[main] DEBUG org.hibernate.SQL - insert into TM_CAMP_JOINT_EMAIL_BODY (CAMP_ID, EMBD_ID) values (?, ?) …
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[main] DEBUG org.hibernate.type.IntegerType - binding '693' to parameter: 1
[main] DEBUG org.hibernate.type.IntegerType - binding '461' to parameter: 2
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - reusing prepared statement
[main] DEBUG org.hibernate.SQL - insert into TM_CAMP_JOINT_EMAIL_BODY (CAMP_ID, EMBD_ID) values (?, ?) …
[main] DEBUG org.hibernate.type.IntegerType - binding '693' to parameter: 1
[main] DEBUG org.hibernate.type.IntegerType - binding '462' to parameter: 2
[main] DEBUG org.hibernate.persister.collection.AbstractCollectionPersister - done inserting collection: 2 rows inserted
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 2
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[main] DEBUG org.hibernate.util.JDBCExceptionReporter - Could not execute JDBC batch update [insert into TM_CAMP_JOINT_EMAIL_BODY (CAMP_ID, EMBD_ID) values (?, ?)]
java.sql.BatchUpdateException: ORA-02291: integrity constraint (TMTEST.FK_EMBD_JEMB) violated - parent key not found

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:498)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:12368)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:171)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at pw.TmDAO.commit(TmDAO.java:30)
at pw.TmCampaignDAO.addCampaign(TmCampaignDAO.java:180)
at pw.TestDAOClient.testAddUpdateCampaign(TestDAOClient.java:114)
at pw.TestDAOClient.main(TestDAOClient.java:36)
……


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.