-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem by cascading save/persist of transient objects
PostPosted: Sun Sep 18, 2005 9:33 am 
Newbie

Joined: Sun Sep 18, 2005 9:05 am
Posts: 4
Hallo,

i'm new using hibernate 3.0.5 and i'm having a problem with it. i want to be sure i did understand everything well:

I have an association like this

[Object A]1--------->*[Object B]1--------->*[Object C]

B has a foreign-key to A's primary-key, C has a foreign-key B's primary-key. all primary-keys are generated

now i've created an instance of A, added at least one instance of B to A and some C instances to C, none of them synchronized to DB (so all of them are transient by now).
than i called session.persist(A) and i'm having the exception as follows.

Mapping documents:
<set name="blockList" order-by="ID_FODE" lazy="true" fetch="select" inverse="true" cascade="all">
<key foreign-key="FOXF03_ID_FODEC">
<column name="ID_FODE" sql-type="$sourceEnd.sqlType"/>
</key>
<one-to-many class="business.model.BlockImpl"/>
</set>


Code for saving:
FormVersion fullFormVersion = (FormVersion)getFullFormVersion();
HibernateUtil.beginnTransaction();

Session session = HibernateUtil.getSession();
session.persist(fullFormVersion);

HibernateUtil.commitTransaction();
HibernateUtil.closeSession();


Full stack trace of any exception that occurs:
org.hibernate.exception.ConstraintViolationException: could not insert: [business.model.BlockImpl]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:63)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1869)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
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.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at business.model.dao.HibernateUtil.commitTransaction(HibernateUtil.java:106)
at test.FormVersionTest.testCascadedCreateFormVersion(FormVersionTest.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:436)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:311)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0530N Der Wert von FOREIGN KEY "DB2POWERUSER.FOXF03.SQL050918105546281" zum Einfügen oder Aktualisieren entspricht keinem Wert des Primärschlüssels der übergeordneten Tabelle. SQLSTATE=23503

at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1853)


Name and version of the database you are using: DB2 version 8


when i have a look at the instances, all primary keys have been created and passed to the refered classes, but at 'commit', the exception accurred, probably because the parent-class has not allready been flushed to DB (so i becomme a problem with the foreign-key of the child class)

my question: is it possible to ifluence the order objects are flushed?
or may i do something to get this running without having to save the parent class, before i save it's children (i wolud like to make use of the 'cascade' capabilities)?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 7:29 pm 
Newbie

Joined: Tue Nov 01, 2005 9:55 pm
Posts: 14
Hi,
I am having the same problem, did you manage to solve it? is it something ni the map files?
tomer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 12:40 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
I'd suggest using Session.save() instead of Session.persist()


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

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.