Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.2.5
Mapping documents:
N/A
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
2009-01-15 10:59:58,422 DEBUG [main] - allowing proxied method [save] to proceed to real session
2009-01-15 10:59:58,453 DEBUG [main] - saving transient instance
2009-01-15 10:59:58,453 DEBUG [main] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2009-01-15 10:59:58,453 DEBUG [main] - preparing statement
2009-01-15 10:59:59,031 DEBUG [main] - Sequence identifier generated: 2088
2009-01-15 10:59:59,047 DEBUG [main] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2009-01-15 10:59:59,047 DEBUG [main] - closing statement
2009-01-15 10:59:59,047 DEBUG [main] - generated identifier: 2088, using strategy: org.hibernate.id.SequenceGenerator
2009-01-15 10:59:59,047 DEBUG [main] - saving [package.B#2088]
2009-01-15 10:59:59,109 DEBUG [main] - allowing proxied method [flush] to proceed to real session
2009-01-15 10:59:59,109 DEBUG [main] - flushing session
2009-01-15 10:59:59,125 DEBUG [main] - processing flush-time cascades
2009-01-15 10:59:59,125 DEBUG [main] - dirty checking collections
2009-01-15 10:59:59,125 DEBUG [main] - Flushing entities and processing referenced collections
2009-01-15 10:59:59,141 DEBUG [main] - Processing unreferenced collections
2009-01-15 10:59:59,141 DEBUG [main] - Scheduling collection removes/(re)creates/updates
2009-01-15 11:00:05,859 DEBUG [main] - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2009-01-15 11:00:11,234 DEBUG [main] - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2009-01-15 11:00:27,360 DEBUG [main] - listing entities:
2009-01-15 11:02:45,455 DEBUG [main] - package.B{someValueB=ValueB, someValueA=ValueA, aId=2088}
2009-01-15 11:02:59,596 DEBUG [main] - executing flush
2009-01-15 11:02:59,596 DEBUG [main] - registering flush begin
2009-01-15 11:04:19,504 DEBUG [main] - Inserting entity: [package.B#2088]
2009-01-15 11:04:40,020 DEBUG [main] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2009-01-15 11:04:40,020 DEBUG [main] - preparing statement
2009-01-15 11:04:49,535 DEBUG [main] - Dehydrating entity: [package.B#2088]
2009-01-15 11:09:36,589 DEBUG [main] - Inserting entity: [package.B#2088]
2009-01-15 11:09:38,074 DEBUG [main] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2009-01-15 11:09:38,074 DEBUG [main] - closing statement
2009-01-15 11:09:38,074 DEBUG [main] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2009-01-15 11:09:38,074 DEBUG [main] - preparing statement
2009-01-15 11:09:38,480 DEBUG [main] - Dehydrating entity: [package.B#2088]
2009-01-15 11:09:40,214 DEBUG [main] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2009-01-15 11:09:40,214 DEBUG [main] - closing statement
2009-01-15 11:09:40,230 DEBUG [main] - could not insert: [package.B] [insert into B (SOME_VALUEB , A_ID) values (?, ?)]
java.sql.SQLException: ORA-02291: integrity constraint (B_A_ID) violated - parent key not found
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:970)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1190)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3370)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3454)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2250)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.flush(Unknown Source)
at package.BTest(BTest.java:25)
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
In stack trace above
Hi there
I am currently experiencing a problem trying to save a subclass B, with parent A.
Consider the following configuration:
Code:
<hibernate-mapping package="package">
<class name="A" table="A">
<id name="aId" type="long" column="A_ID">
<generator class="sequence">
<param name="sequence">A_SEQ</param>
</generator>
</id>
<property name="someValueA" column="SOME_VALUEA" not-null="false"/>
<joined-subclass name="package.B" table="B">
<key column="A_ID"/>
<property name="someValueB" column="SOME_VALUEB" not-null="true"/>
</joined-subclass>
</class>
</hibernate-mapping>
, and the following table tructure:
Code:
Table A:
A_ID (PK)
SOME_VALUEA
Table B:
SOME_VALUEB
A_ID (FK)
I then call the following:
Code:
Session session = InitSessionFactory.getInstance().getCurrentSession();
session.save(b); // save the subclass
session.flush(); // just to propagate the exception
, which results in the following SQLException:
integrity constraint violated - parent key not found
I debugged some of the hibernate code and both inserts, parent table insert followed by child table insert, are executed, but when the second (child) insert takes place, it's as if the first statement has not really been inserted to the database. The foreign key of child insert does not exist as a primary key in the parent table, hence the constraint violation.
Any help/pointers on this would be much appreciated. I've tried to figure out what is going on myself, but I'm at the point where I need some assistance.
Thank you
Pat Considine