-->
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.  [ 2 posts ] 
Author Message
 Post subject: cascade insert - update from a parent to distinguished child
PostPosted: Tue Jan 02, 2007 5:52 am 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
I have a Parent - Child relation where the parent has a distinguished (principal) child.
I want to cascade insert-update operations from the parent to the principal child, but for creation, hibernate tries to insert a child with a null value for the parent_id column (which is not -null).

Any ideas ?

Hibernate version: 3.2.1

Mapping documents:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="domain">

  <class name="Parent" table="TEST_PARENT" >

      <id name="id" column="ID">
          <generator class="sequence">
               <param name="sequence">FCT_SEQEMP</param>
          </generator>
      </id>

      <property name="name" column="NAME" />

      <set name="childs" lazy="true" inverse="true" cascade="none">
          <key column="PARENT_ID" />
          <one-to-many class="Child" />
      </set>

      <many-to-one name="principalChild" column="PRINCIPAL_CHILD" class="Child" cascade="all" />

  </class>

  <class name="Child" table="TEST_CHILD">

      <id name="id" column="ID" >
          <generator class="sequence">
               <param name="sequence">FCT_SEQCTR</param>
          </generator>
      </id>

      <property name="name" column="NAME" />

      <many-to-one name="parent" column="PARENT_ID"  cascade="none"/>

  </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Code:
            txt =  session.beginTransaction();
            Parent parent = new Parent();
            parent.setName("parent");

            Child child = new Child();
            child.setName("child");
            child.setParent(parent);

            parent.getChilds().add(child);
            parent.setPrincipalChild(child);

            session.save(parent);

            txt.commit();


Full stack trace of any exception that occurs:

Code:
     [java]  INFO [main] (SessionFactoryImpl.java:161) - building session factory
     [java]  INFO [main] (SessionFactoryObjectFactory.java:82) - Not binding factory to JNDI, no JNDI name configured
     [java] hashCode child
     [java] Hibernate: select FCT_SEQEMP.nextval from dual
     [java] Hibernate: select FCT_SEQCTR.nextval from dual
     [java] hashCode child
     [java] Hibernate: insert into TEST_CHILD (NAME, PARENT_ID, ID) values (?, ?, ?)
     [java]  WARN [main] (JDBCExceptionReporter.java:77) - SQL Error: 1400, SQLState: 23000
     [java] ERROR [main] (JDBCExceptionReporter.java:78) - ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARE
NT_ID")

     [java]  WARN [main] (JDBCExceptionReporter.java:77) - SQL Error: 1400, SQLState: 23000
     [java] ERROR [main] (JDBCExceptionReporter.java:78) - ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARE
NT_ID")

     [java] ERROR [main] (AbstractFlushingEventListener.java:301) - Could not synchronize database state with session
     [java] org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
     [java]     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
     [java]     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
     [java]     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
     [java]     at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
     [java]     at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
     [java]     at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2174)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)
     [java]     at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)
     [java]     at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
     [java]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
     [java]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
     [java]     at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)

     [java]     at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
     [java]     at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
     [java]     at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
     [java]     at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
     [java]     at test.Main.main(Main.java:44)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java]     at java.lang.reflect.Method.invoke(Method.java:324)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
     [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
     [java]     at org.apache.tools.ant.Task.perform(Task.java:364)
     [java]     at org.apache.tools.ant.Target.execute(Target.java:341)
     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:369)
     [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
     [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:668)
     [java]     at org.apache.tools.ant.Main.startAnt(Main.java:187)
     [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
     [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
     [java] Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARENT_ID
")

     [java]     at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
     [java]     at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
     [java]     at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
     [java]     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
     [java]     ... 36 more
     [java] org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
     [java]     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
     [java]     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
     [java]     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
     [java]     at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
     [java]     at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
     [java]     at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2174)
     [java]     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)
     [java]     at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)
     [java]     at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
     [java]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
     [java]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
     [java]     at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)

     [java]     at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
     [java]     at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
     [java]     at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
     [java]     at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
     [java]     at test.Main.main(Main.java:44)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java]     at java.lang.reflect.Method.invoke(Method.java:324)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
     [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
     [java]     at org.apache.tools.ant.Task.perform(Task.java:364)
     [java]     at org.apache.tools.ant.Target.execute(Target.java:341)
     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:369)
     [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
     [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:668)
     [java]     at org.apache.tools.ant.Main.startAnt(Main.java:187)
     [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
     [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
     [java] Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARENT_ID
")

     [java]     at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
     [java]     at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
     [java]     at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
     [java]     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
     [java]     ... 36 more


Name and version of the database you are using:
Oracle 9.2.0.5.0

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

    [java] DEBUG [main] (SessionImpl.java:220) - opened session at timestamp: 11677307094
    [java] DEBUG [main] (JDBCTransaction.java:54) - begin
    [java] DEBUG [main] (ConnectionManager.java:415) - opening JDBC connection
    [java] DEBUG [main] (DriverManagerConnectionProvider.java:93) - total checked-out connections: 0
    [java] DEBUG [main] (DriverManagerConnectionProvider.java:99) - using pooled JDBC connection, pool size: 0
    [java] DEBUG [main] (JDBCTransaction.java:59) - current autocommit status: false
    [java] DEBUG [main] (JDBCContext.java:210) - after transaction begin
    [java] hashCode child
    [java] DEBUG [main] (DefaultSaveOrUpdateEventListener.java:161) - saving transient instance
    [java] DEBUG [main] (AbstractBatcher.java:358) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    [java] DEBUG [main] (AbstractBatcher.java:393) - select FCT_SEQEMP.nextval from dual
    [java] Hibernate: select FCT_SEQEMP.nextval from dual
    [java] DEBUG [main] (AbstractBatcher.java:476) - preparing statement
    [java] DEBUG [main] (SequenceGenerator.java:82) - Sequence identifier generated: 123
    [java] DEBUG [main] (AbstractBatcher.java:366) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    [java] DEBUG [main] (AbstractBatcher.java:525) - closing statement
    [java] DEBUG [main] (AbstractSaveEventListener.java:113) - generated identifier: 123, using strategy: org.hibernate.id.Sequen
    ceGenerator
    [java] DEBUG [main] (AbstractSaveEventListener.java:152) - saving [domain.Parent#123]
    [java] DEBUG [main] (Cascade.java:115) - processing cascade ACTION_SAVE_UPDATE for: domain.Parent
    [java] DEBUG [main] (CascadingAction.java:216) - cascading to saveOrUpdate: domain.Child
    [java] DEBUG [main] (AbstractSaveEventListener.java:489) - transient instance of: domain.Child
    [java] DEBUG [main] (DefaultSaveOrUpdateEventListener.java:161) - saving transient instance
    [java] DEBUG [main] (AbstractBatcher.java:358) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    [java] DEBUG [main] (AbstractBatcher.java:393) - select FCT_SEQCTR.nextval from dual
    [java] Hibernate: select FCT_SEQCTR.nextval from dual
    [java] DEBUG [main] (AbstractBatcher.java:476) - preparing statement
    [java] DEBUG [main] (SequenceGenerator.java:82) - Sequence identifier generated: 111
    [java] DEBUG [main] (AbstractBatcher.java:366) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    [java] DEBUG [main] (AbstractBatcher.java:525) - closing statement
    [java] DEBUG [main] (AbstractSaveEventListener.java:113) - generated identifier: 111, using strategy: org.hibernate.id.Sequen
    ceGenerator
    [java] DEBUG [main] (AbstractSaveEventListener.java:152) - saving [domain.Child#111]
    [java] DEBUG [main] (Cascade.java:150) - done processing cascade ACTION_SAVE_UPDATE for: domain.Parent
    [java] hashCode child
    [java] DEBUG [main] (WrapVisitor.java:87) - Wrapped collection in role: domain.Parent.childs
    [java] DEBUG [main] (Cascade.java:115) - processing cascade ACTION_SAVE_UPDATE for: domain.Parent
    [java] DEBUG [main] (Cascade.java:150) - done processing cascade ACTION_SAVE_UPDATE for: domain.Parent
    [java] DEBUG [main] (JDBCTransaction.java:103) - commit
    [java] DEBUG [main] (SessionImpl.java:337) - automatically flushing session
    [java] DEBUG [main] (AbstractFlushingEventListener.java:58) - flushing session
    [java] DEBUG [main] (AbstractFlushingEventListener.java:111) - processing flush-time cascades
    [java] DEBUG [main] (Cascade.java:115) - processing cascade ACTION_SAVE_UPDATE for: domain.Parent
    [java] DEBUG [main] (CascadingAction.java:216) - cascading to saveOrUpdate: domain.Child
    [java] DEBUG [main] (AbstractSaveEventListener.java:463) - persistent instance of: domain.Child
    [java] DEBUG [main] (DefaultSaveOrUpdateEventListener.java:105) - ignoring persistent instance
    [java] DEBUG [main] (DefaultSaveOrUpdateEventListener.java:142) - object already associated with session: [domain.Child#111]
    [java] DEBUG [main] (Cascade.java:150) - done processing cascade ACTION_SAVE_UPDATE for: domain.Parent
    [java] DEBUG [main] (AbstractFlushingEventListener.java:154) - dirty checking collections
    [java] DEBUG [main] (AbstractFlushingEventListener.java:171) - Flushing entities and processing referenced collections
    [java] DEBUG [main] (AbstractEntityPersister.java:3131) - domain.Child.parent is dirty
    [java] DEBUG [main] (DefaultFlushEntityEventListener.java:229) - Updating entity: [domain.Child#111]
    [java] DEBUG [main] (Collections.java:176) - Collection found: [domain.Parent.childs#123], was: [<unreferenced>] (initialized
    )
    [java] DEBUG [main] (AbstractFlushingEventListener.java:210) - Processing unreferenced collections
    [java] DEBUG [main] (AbstractFlushingEventListener.java:224) - Scheduling collection removes/(re)creates/updates
    [java] DEBUG [main] (AbstractFlushingEventListener.java:85) - Flushed: 2 insertions, 1 updates, 0 deletions to 2 objects
    [java] DEBUG [main] (AbstractFlushingEventListener.java:91) - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collection
    s
    [java] DEBUG [main] (Printer.java:83) - listing entities:
    [java] DEBUG [main] (Printer.java:90) - domain.Parent{childs=[domain.Child#111], name=parent, principalChild=domain.Child#111
    , id=123}
    [java] DEBUG [main] (Printer.java:90) - domain.Child{name=child, parent=domain.Parent#123, id=111}
    [java] DEBUG [main] (AbstractFlushingEventListener.java:290) - executing flush
    [java] DEBUG [main] (ConnectionManager.java:463) - registering flush begin
    [java] DEBUG [main] (AbstractEntityPersister.java:2154) - Inserting entity: [domain.Child#111]
    [java] DEBUG [main] (AbstractBatcher.java:358) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    [java] DEBUG [main] (AbstractBatcher.java:393) - insert into TEST_CHILD (NAME, PARENT_ID, ID) values (?, ?, ?)
    [java] Hibernate: insert into TEST_CHILD (NAME, PARENT_ID, ID) values (?, ?, ?)
    [java] DEBUG [main] (AbstractBatcher.java:476) - preparing statement
    [java] DEBUG [main] (AbstractEntityPersister.java:1942) - Dehydrating entity: [domain.Child#111]
    [java] DEBUG [main] (NullableType.java:80) - binding 'child' to parameter: 1
    [java] DEBUG [main] (NullableType.java:73) - binding null to parameter: 2
    [java] DEBUG [main] (NullableType.java:80) - binding '111' to parameter: 3
    [java] DEBUG [main] (AbstractEntityPersister.java:2154) - Inserting entity: [domain.Parent#123]
    [java] DEBUG [main] (BatchingBatcher.java:44) - Executing batch size: 1
    [java] DEBUG [main] (AbstractBatcher.java:366) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    [java] DEBUG [main] (AbstractBatcher.java:525) - closing statement
    [java] DEBUG [main] (JDBCExceptionReporter.java:69) - Could not execute JDBC batch update [insert into TEST_CHILD (NAME, PARE
    NT_ID, ID) values (?, ?, ?)]
    [java] java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARENT_ID")

    [java] at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
    [java] at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
    [java] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    [java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
    [java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2174)
    [java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)
    [java] at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)
    [java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
    [java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
    [java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    [java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)

    [java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    [java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    [java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    [java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    [java] at test.Main.main(Main.java:44)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [java] at java.lang.reflect.Method.invoke(Method.java:324)
    [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
    [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
    [java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
    [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
    [java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
    [java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    [java] at org.apache.tools.ant.Task.perform(Task.java:364)
    [java] at org.apache.tools.ant.Target.execute(Target.java:341)
    [java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
    [java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    [java] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
    [java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
    [java] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    [java] at org.apache.tools.ant.Main.runBuild(Main.java:668)
    [java] at org.apache.tools.ant.Main.startAnt(Main.java:187)
    [java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
    [java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
    [java] WARN [main] (JDBCExceptionReporter.java:77) - SQL Error: 1400, SQLState: 23000
    [java] ERROR [main] (JDBCExceptionReporter.java:78) - ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARE
    NT_ID")

    [java] WARN [main] (JDBCExceptionReporter.java:77) - SQL Error: 1400, SQLState: 23000
    [java] ERROR [main] (JDBCExceptionReporter.java:78) - ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARE
    NT_ID")

    [java] ERROR [main] (AbstractFlushingEventListener.java:301) - Could not synchronize database state with session
    [java] org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
    [java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    [java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    [java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
    [java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2174)
    [java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)
    [java] at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)
    [java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
    [java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
    [java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    [java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)

    [java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    [java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    [java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    [java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    [java] at test.Main.main(Main.java:44)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [java] at java.lang.reflect.Method.invoke(Method.java:324)
    [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
    [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
    [java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
    [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
    [java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
    [java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    [java] at org.apache.tools.ant.Task.perform(Task.java:364)
    [java] at org.apache.tools.ant.Target.execute(Target.java:341)
    [java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
    [java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    [java] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
    [java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
    [java] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    [java] at org.apache.tools.ant.Main.runBuild(Main.java:668)
    [java] at org.apache.tools.ant.Main.startAnt(Main.java:187)
    [java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
    [java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
    [java] Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARENT_ID
    ")

    [java] at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
    [java] at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
    [java] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    [java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
    [java] ... 36 more
    [java] DEBUG [main] (ConnectionManager.java:472) - registering flush end
    [java] org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
    [java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    [java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    [java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
    [java] at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
    [java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2174)
    [java] at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)
    [java] at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)
    [java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
    [java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
    [java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    [java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)

    [java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    [java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    [java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    [java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    [java] at test.Main.main(Main.java:44)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [java] at java.lang.reflect.Method.invoke(Method.java:324)
    [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
    [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)
    [java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
    [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
    [java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
    [java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    [java] at org.apache.tools.ant.Task.perform(Task.java:364)
    [java] at org.apache.tools.ant.Target.execute(Target.java:341)
    [java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
    [java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    [java] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
    [java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
    [java] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    [java] at org.apache.tools.ant.Main.runBuild(Main.java:668)
    [java] at org.apache.tools.ant.Main.startAnt(Main.java:187)
    [java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
    [java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
    [java] Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("DOMINGO_FORCET"."TEST_CHILD"."PARENT_ID
    ")

    [java] at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
    [java] at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4210)
    [java] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    [java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
    [java] ... 36 more
    [java] DEBUG [main] (SessionImpl.java:273) - closing session
    [java] DEBUG [main] (ConnectionManager.java:374) - performing cleanup
    [java] DEBUG [main] (ConnectionManager.java:435) - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (ope
    n ResultSets: 0, globally: 0)]
    [java] DEBUG [main] (DriverManagerConnectionProvider.java:129) - returning connection to pool, pool size: 1

POJOs are:

Code:
public class Parent {

    private Long id;
    private String name;
    private Child principalChild;
    private Set childs = new HashSet();

    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public Child getPrincipalChild() { return principalChild; }
    public void setPrincipalChild(Child principalChild) { this.principalChild = principalChild;}

    public Set getChilds() { return childs; }
    public void setChilds(Set childs) { this.childs = childs; }


    public boolean equals(Object o) {
        System.out.println("equals parent");
        if (this == o) return true;
        if (o == null || !(o instanceof Parent)) return false;

        Parent parent = (Parent) o;

        if (!name.equals(parent.name)) return false;

        return true;
    }

    public int hashCode() {
        System.out.println("hash parent");
        return name.hashCode();
    }
}



Code:
public class Child {

    private Long id;
    private String name;
    private Parent parent;

    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public Parent getParent() { return parent; }
    public void setParent(Parent parent) { this.parent = parent; }

    public boolean equals(Object o) {
        System.out.println("equals child");
        if (this == o) return true;
        if (o == null || !(o instanceof Child)) return false;

        Child child = (Child) o;

        if (!name.equals(child.name)) return false;

        return true;
    }

    public int hashCode() {
        System.out.println("hashCode child");
        return name.hashCode();
    }

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 6:54 pm 
Newbie

Joined: Wed Sep 14, 2005 5:51 pm
Posts: 1
Hi, I ran into exactly the same problem.

I had to save the Parent first and then set the parent's id on the child:

.
.
HibernateSessionManager.getSession().save(Parent);
.
.
child.setParentId(Parent.getId());
.
.
.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.