-->
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.  [ 5 posts ] 
Author Message
 Post subject: Extra insert with unidirectional many-to-many & cascade
PostPosted: Thu May 12, 2005 5:13 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
I have a unidirectional many-to-many with cascade="save-update". When I create a new transient parent, and attach a transient item to the Set (many-to-many) and call save(), I get TWO inserts for child entities (into the join table). The first insert is OK, and contains both the parent and child ID's. The second insert contains the parent ID, but no child ID, hence the ORA-01400: cannot insert NULL jazz. I'm totally stumped here.

I have snipped out some verbose portions of my mapping docs.

Hibernate version:
2.1.8

Mapping documents:
Code:
<hibernate-mapping>
   <class name="com.comerxia.core.model.Account" table="ACCOUNT"
      dynamic-update="false" dynamic-insert="false"
      select-before-update="false" optimistic-lock="version">

      <id name="id" column="ID" type="java.lang.Long">
         <generator class="sequence">
            <param name="sequence">ACCOUNT_SEQ</param>
         </generator>
      </id>

      <set name="addresses" table="LINKACCOUNTADDRESS" lazy="false"
         inverse="false" cascade="save-update" sort="unsorted">

         <key column="ACCOUNTID" foreign-key="LAA_ACCOUNTID_FK">
         </key>

         <many-to-many class="com.comerxia.core.model.Address"
            column="ADDRESSID" outer-join="auto" foreign-key="LAA_ADDRESSID_FK" />

      </set>
   </class>

</hibernate-mapping>


Code:
<hibernate-mapping>
   <class name="com.comerxia.core.model.Address" table="ADDRESS"
      lazy="true" dynamic-update="false" dynamic-insert="false"
      select-before-update="false" optimistic-lock="version"
      discriminator-value="null">

      <id name="id" column="ID" type="java.lang.Long">
         <generator class="sequence">
            <param name="sequence">ADDRESS_SEQ</param>
         </generator>
      </id>

      <discriminator column="TYPE" />

      <property name="description" type="java.lang.String"
         update="true" insert="true" access="property" column="DESCRIPTION"
         length="50" not-null="true" />

      <many-to-one name="country"
         class="com.comerxia.core.model.Country" cascade="none"
         outer-join="auto" update="true" insert="true" access="property"
         foreign-key="ADDRESS_COUNTRYCODE_FK" column="COUNTRYCODE" />

      <property name="dateCreated" type="java.util.Date" update="true"
         insert="true" access="property" column="DATECREATED" />

      <subclass name="com.comerxia.core.model.WarehouseAddress"
         dynamic-update="false" dynamic-insert="false" lazy="true"
         discriminator-value="WAREHOUSE">
         <property name="code" type="java.lang.String" update="true"
            insert="true" access="property" column="CODE" unique="true" />
      </subclass>

   </class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
I'm using Spring with declarative transaction demarcation and what
acts like OpenSessionInViewFilter (actually it is a base Spring JUnit test case that works the same way).
Code:
return (Long) getHibernateTemplate().save(bean);



Full stack trace of any exception that occurs:
See below...

Name and version of the database you are using:
Oracle 8i

The generated SQL (show_sql=true):
Code:
Hibernate: select ACCOUNT_SEQ.nextval from dual
Hibernate: select ADDRESS_SEQ.nextval from dual
Hibernate: insert into CORE.ACCOUNT (ENABLEDFLAG, EMAILADDRESS, FIRSTNAME, MIDDLENAME, LASTNAME, GENERATEDEMAILADDRESS, GOSHOPPINGREGID, LOCALECODE, MALLID, MERCHANTID, MERCHANTCUSTOMERID, PASSWORD, PASSWORDHINTANSWER, PASSWORDHINTQUESTION, BILLTOADDRESSID, SHIPTOADDRESSID, SUBSCRIBEDFLAG, DATECREATED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into CORE.ADDRESS (DESCRIPTION, CITY, FIRSTNAME, LASTNAME, MIDDLENAME, PHONE, STATE, STREET1, STREET2, POSTALCODE, NATIONALID, COUNTRYCODE, DATECREATED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into CORE.LINKACCOUNTADDRESS (ACCOUNTID, ADDRESSID) values (?, ?)
Hibernate: insert into CORE.LINKACCOUNTADDRESS (ACCOUNTID, ADDRESSID) values (?, ?)


Debug level Hibernate log excerpt:
Code:
2005-05-12 16:57:18,562 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:204) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:18,577 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:230) - select ACCOUNT_SEQ.nextval from dual
Hibernate: select ACCOUNT_SEQ.nextval from dual
2005-05-12 16:57:18,577 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:253) - preparing statement
2005-05-12 16:57:18,593 DEBUG [main] id.SequenceGenerator (SequenceGenerator.java:76) - Sequence identifier generated: 708
2005-05-12 16:57:18,593 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:211) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:18,608 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:275) - closing statement
2005-05-12 16:57:18,608 DEBUG [main] impl.SessionImpl (SessionImpl.java:789) - generated identifier: 708
2005-05-12 16:57:18,608 DEBUG [main] impl.SessionImpl (SessionImpl.java:836) - saving [com.comerxia.core.model.Account#708]
2005-05-12 16:57:18,624 DEBUG [main] engine.Cascades (Cascades.java:497) - processing cascades for: com.comerxia.core.model.Account
2005-05-12 16:57:18,640 DEBUG [main] engine.Cascades (Cascades.java:506) - done processing cascades for: com.comerxia.core.model.Account
2005-05-12 16:57:18,640 DEBUG [main] impl.WrapVisitor (WrapVisitor.java:81) - Wrapped collection in role: com.comerxia.core.model.Account.addresses
2005-05-12 16:57:18,655 DEBUG [main] engine.Cascades (Cascades.java:497) - processing cascades for: com.comerxia.core.model.Account
2005-05-12 16:57:18,655 DEBUG [main] engine.Cascades (Cascades.java:524) - cascading to collection: com.comerxia.core.model.Account.addresses
2005-05-12 16:57:18,671 DEBUG [main] engine.Cascades$4 (Cascades.java:113) - cascading to saveOrUpdate()
2005-05-12 16:57:18,671 DEBUG [main] impl.SessionImpl (SessionImpl.java:1397) - saveOrUpdate() unsaved instance
2005-05-12 16:57:18,687 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:204) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:18,687 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:230) - select ADDRESS_SEQ.nextval from dual
Hibernate: select ADDRESS_SEQ.nextval from dual
2005-05-12 16:57:18,702 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:253) - preparing statement
2005-05-12 16:57:18,718 DEBUG [main] id.SequenceGenerator (SequenceGenerator.java:76) - Sequence identifier generated: 2678
2005-05-12 16:57:18,733 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:211) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:18,733 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:275) - closing statement
2005-05-12 16:57:18,749 DEBUG [main] impl.SessionImpl (SessionImpl.java:789) - generated identifier: 2678
2005-05-12 16:57:18,749 DEBUG [main] impl.SessionImpl (SessionImpl.java:836) - saving [com.comerxia.core.model.Address#2678]
2005-05-12 16:57:18,765 DEBUG [main] engine.Cascades (Cascades.java:506) - done processing cascades for: com.comerxia.core.model.Account
2005-05-12 16:57:18,765 DEBUG [main] support.TransactionSynchronizationManager (TransactionSynchronizationManager.java:127) - Retrieved value [org.springframework.orm.hibernate.SessionHolder@6dd8e1] for key [net.sf.hibernate.impl.SessionFactoryImpl@1c0cb76] bound to thread [main]
2005-05-12 16:57:22,218 DEBUG [main] interceptor.TransactionAspectSupport (TransactionAspectSupport.java:241) - Invoking commit for transaction on method 'createAccount' in class [com.comerxia.core.logic.AccountManager]
2005-05-12 16:57:22,218 DEBUG [main] support.AbstractPlatformTransactionManager (AbstractPlatformTransactionManager.java:523) - Triggering beforeCommit synchronization
2005-05-12 16:57:22,233 DEBUG [main] support.AbstractPlatformTransactionManager (AbstractPlatformTransactionManager.java:538) - Triggering beforeCompletion synchronization
2005-05-12 16:57:22,233 DEBUG [main] support.AbstractPlatformTransactionManager (AbstractPlatformTransactionManager.java:396) - Initiating transaction commit
2005-05-12 16:57:22,249 DEBUG [main] hibernate.HibernateTransactionManager (HibernateTransactionManager.java:468) - Committing Hibernate transaction on session [net.sf.hibernate.impl.SessionImpl@178feba]
2005-05-12 16:57:22,249 DEBUG [main] transaction.JDBCTransaction (JDBCTransaction.java:59) - commit
2005-05-12 16:57:22,249 DEBUG [main] impl.SessionImpl (SessionImpl.java:2267) - flushing session
2005-05-12 16:57:22,265 DEBUG [main] engine.Cascades (Cascades.java:497) - processing cascades for: com.comerxia.core.model.Account
2005-05-12 16:57:22,265 DEBUG [main] engine.Cascades (Cascades.java:524) - cascading to collection: com.comerxia.core.model.Account.addresses
2005-05-12 16:57:22,280 DEBUG [main] engine.Cascades$4 (Cascades.java:113) - cascading to saveOrUpdate()
2005-05-12 16:57:22,280 DEBUG [main] impl.SessionImpl (SessionImpl.java:1382) - saveOrUpdate() persistent instance
2005-05-12 16:57:22,280 DEBUG [main] engine.Cascades (Cascades.java:506) - done processing cascades for: com.comerxia.core.model.Account
2005-05-12 16:57:22,296 DEBUG [main] impl.SessionImpl (SessionImpl.java:2467) - Flushing entities and processing referenced collections
2005-05-12 16:57:22,296 DEBUG [main] impl.SessionImpl (SessionImpl.java:2916) - Collection found: [com.comerxia.core.model.Merchant.users#1], was: [com.comerxia.core.model.Merchant.users#1]
2005-05-12 16:57:22,296 DEBUG [main] impl.SessionImpl (SessionImpl.java:2916) - Collection found: [com.comerxia.core.model.Account.addresses#708], was: [<unreferenced>]
2005-05-12 16:57:22,312 DEBUG [main] impl.SessionImpl (SessionImpl.java:2808) - Processing unreferenced collections
2005-05-12 16:57:22,312 DEBUG [main] impl.SessionImpl (SessionImpl.java:2822) - Scheduling collection removes/(re)creates/updates
2005-05-12 16:57:22,327 DEBUG [main] impl.SessionImpl (SessionImpl.java:2291) - Flushed: 2 insertions, 0 updates, 0 deletions to 3 objects
2005-05-12 16:57:22,343 DEBUG [main] impl.SessionImpl (SessionImpl.java:2296) - Flushed: 1 (re)creations, 0 updates, 0 removals to 2 collections
2005-05-12 16:57:22,343 DEBUG [main] impl.Printer (Printer.java:75) - listing entities:
2005-05-12 16:57:22,358 DEBUG [main] impl.Printer (Printer.java:82) - com.comerxia.core.model.Address{phone=null, dateCreated=null, id=2678, firstName=null, lastName=null, street2=Suite 200, postalCode=33020, nationalId=null, country=null, street1=1900 Tyler Street, description=desc, state=Florida, middleName=null, city=Hollywood}
2005-05-12 16:57:22,374 DEBUG [main] impl.Printer (Printer.java:82) - com.comerxia.core.model.Account{addresses=[Address#2678, null], password=null, merchant=Merchant#1, subscribed=null, shipToAddress=null, dateCreated=2005-05-12 16:57:18, id=708, firstName=JUnit, lastName=Test, passwordHintQuestion=null, goShoppingRegId=null, mallId=null, enabled=true, merchantCustomerId=test1115931427655, emailAddress=junit1115931427655@comerxia.com, localeCode=null, billToAddress=null, middleName=null, generatedEmailAddress=null, passwordHintAnswer=null}
2005-05-12 16:57:22,374 DEBUG [main] impl.Printer (Printer.java:82) - com.comerxia.core.model.Merchant{webServiceUserId=121, code=COMERXIA, enabled=true, users=uninitialized, description=Comerxia, legacySiteId=null, webServiceKey=COMERXIA, merchantGroup=MerchantGroup#1, legacyCobrandId=null, dateCreated=2005-04-07 16:04:35, id=1}
2005-05-12 16:57:22,374 DEBUG [main] impl.SessionImpl (SessionImpl.java:2380) - executing flush
2005-05-12 16:57:22,390 DEBUG [main] persister.EntityPersister (EntityPersister.java:447) - Inserting entity: [com.comerxia.core.model.Account#708]
2005-05-12 16:57:22,390 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:204) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:22,390 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:230) - insert into CORE.ACCOUNT (ENABLEDFLAG, EMAILADDRESS, FIRSTNAME, MIDDLENAME, LASTNAME, GENERATEDEMAILADDRESS, GOSHOPPINGREGID, LOCALECODE, MALLID, MERCHANTID, MERCHANTCUSTOMERID, PASSWORD, PASSWORDHINTANSWER, PASSWORDHINTQUESTION, BILLTOADDRESSID, SHIPTOADDRESSID, SUBSCRIBEDFLAG, DATECREATED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into CORE.ACCOUNT (ENABLEDFLAG, EMAILADDRESS, FIRSTNAME, MIDDLENAME, LASTNAME, GENERATEDEMAILADDRESS, GOSHOPPINGREGID, LOCALECODE, MALLID, MERCHANTID, MERCHANTCUSTOMERID, PASSWORD, PASSWORDHINTANSWER, PASSWORDHINTQUESTION, BILLTOADDRESSID, SHIPTOADDRESSID, SUBSCRIBEDFLAG, DATECREATED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2005-05-12 16:57:22,405 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:253) - preparing statement
2005-05-12 16:57:22,421 DEBUG [main] persister.EntityPersister (EntityPersister.java:382) - Dehydrating entity: [com.comerxia.core.model.Account#708]
2005-05-12 16:57:22,421 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'true' to parameter: 1
2005-05-12 16:57:22,437 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'junit1115931427655@comerxia.com' to parameter: 2
2005-05-12 16:57:22,437 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'JUnit' to parameter: 3
2005-05-12 16:57:22,452 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 4
2005-05-12 16:57:22,452 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'Test' to parameter: 5
2005-05-12 16:57:22,468 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 6
2005-05-12 16:57:22,468 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 7
2005-05-12 16:57:22,483 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 8
2005-05-12 16:57:22,483 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 9
2005-05-12 16:57:22,483 DEBUG [main] type.NullableType (NullableType.java:46) - binding '1' to parameter: 10
2005-05-12 16:57:22,499 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'test1115931427655' to parameter: 11
2005-05-12 16:57:22,499 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 12
2005-05-12 16:57:22,515 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 13
2005-05-12 16:57:22,515 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 14
2005-05-12 16:57:22,530 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 15
2005-05-12 16:57:22,530 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 16
2005-05-12 16:57:22,546 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 17
2005-05-12 16:57:22,562 DEBUG [main] type.NullableType (NullableType.java:46) - binding '2005-05-12 16:57:18' to parameter: 18
2005-05-12 16:57:22,562 DEBUG [main] type.NullableType (NullableType.java:46) - binding '708' to parameter: 19
2005-05-12 16:57:22,577 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:28) - Adding to batch
2005-05-12 16:57:22,577 DEBUG [main] persister.EntityPersister (EntityPersister.java:447) - Inserting entity: [com.comerxia.core.model.Address#2678]
2005-05-12 16:57:22,577 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:50) - Executing batch size: 1
2005-05-12 16:57:22,593 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-05-12 16:57:22,593 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:211) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:22,608 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:275) - closing statement
2005-05-12 16:57:22,608 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:204) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:22,624 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:230) - insert into CORE.ADDRESS (DESCRIPTION, CITY, FIRSTNAME, LASTNAME, MIDDLENAME, PHONE, STATE, STREET1, STREET2, POSTALCODE, NATIONALID, COUNTRYCODE, DATECREATED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into CORE.ADDRESS (DESCRIPTION, CITY, FIRSTNAME, LASTNAME, MIDDLENAME, PHONE, STATE, STREET1, STREET2, POSTALCODE, NATIONALID, COUNTRYCODE, DATECREATED, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2005-05-12 16:57:22,624 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:253) - preparing statement
2005-05-12 16:57:22,640 DEBUG [main] persister.EntityPersister (EntityPersister.java:382) - Dehydrating entity: [com.comerxia.core.model.Address#2678]
2005-05-12 16:57:22,640 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'desc' to parameter: 1
2005-05-12 16:57:22,655 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'Hollywood' to parameter: 2
2005-05-12 16:57:22,655 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 3
2005-05-12 16:57:22,655 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 4
2005-05-12 16:57:22,671 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 5
2005-05-12 16:57:22,671 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 6
2005-05-12 16:57:22,671 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'Florida' to parameter: 7
2005-05-12 16:57:22,687 DEBUG [main] type.NullableType (NullableType.java:46) - binding '1900 Tyler Street' to parameter: 8
2005-05-12 16:57:22,687 DEBUG [main] type.NullableType (NullableType.java:46) - binding 'Suite 200' to parameter: 9
2005-05-12 16:57:22,687 DEBUG [main] type.NullableType (NullableType.java:46) - binding '33020' to parameter: 10
2005-05-12 16:57:22,702 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 11
2005-05-12 16:57:22,702 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 12
2005-05-12 16:57:22,702 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 13
2005-05-12 16:57:22,718 DEBUG [main] type.NullableType (NullableType.java:46) - binding '2678' to parameter: 14
2005-05-12 16:57:22,718 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:28) - Adding to batch
2005-05-12 16:57:22,733 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:50) - Executing batch size: 1
2005-05-12 16:57:22,749 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:58) - success of batch update unknown: 0
2005-05-12 16:57:22,749 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:211) - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:22,749 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:275) - closing statement
2005-05-12 16:57:22,765 DEBUG [main] collection.AbstractCollectionPersister (AbstractCollectionPersister.java:510) - Inserting collection: [com.comerxia.core.model.Account.addresses#708]
2005-05-12 16:57:22,765 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:204) - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-05-12 16:57:22,765 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:230) - insert into CORE.LINKACCOUNTADDRESS (ACCOUNTID, ADDRESSID) values (?, ?)
Hibernate: insert into CORE.LINKACCOUNTADDRESS (ACCOUNTID, ADDRESSID) values (?, ?)
2005-05-12 16:57:22,780 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:253) - preparing statement
2005-05-12 16:57:22,780 DEBUG [main] type.NullableType (NullableType.java:46) - binding '708' to parameter: 1
2005-05-12 16:57:22,796 DEBUG [main] type.NullableType (NullableType.java:46) - binding '2678' to parameter: 2
2005-05-12 16:57:22,796 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:28) - Adding to batch
2005-05-12 16:57:22,796 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:115) - reusing prepared statement
2005-05-12 16:57:22,812 DEBUG [main] impl.BatcherImpl (BatcherImpl.java:230) - insert into CORE.LINKACCOUNTADDRESS (ACCOUNTID, ADDRESSID) values (?, ?)
Hibernate: insert into CORE.LINKACCOUNTADDRESS (ACCOUNTID, ADDRESSID) values (?, ?)
2005-05-12 16:57:22,812 DEBUG [main] type.NullableType (NullableType.java:46) - binding '708' to parameter: 1
2005-05-12 16:57:22,827 DEBUG [main] type.NullableType (NullableType.java:41) - binding null to parameter: 2
2005-05-12 16:57:22,827 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:28) - Adding to batch
2005-05-12 16:57:22,843 DEBUG [main] collection.AbstractCollectionPersister (AbstractCollectionPersister.java:532) - done inserting collection: 2 rows inserted
2005-05-12 16:57:22,843 DEBUG [main] impl.BatchingBatcher (BatchingBatcher.java:50) - Executing batch size: 2
2005-05-12 16:57:22,874 DEBUG [main] util.JDBCExceptionReporter (JDBCExceptionReporter.java:49) - SQL Exception
java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("CORE"."LINKACCOUNTADDRESS"."ADDRESSID")

   at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:128)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2396)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at org.springframework.orm.hibernate.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:472)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 5:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
did you check you equals/hashcode implementation?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 10:04 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Quote:
did you check you equals/hashcode implementation?


No, but I'm now engaged in the debate with my colleagues over how to implement .equals() and .hashCode(), making my way through postings and Wiki pages (lots to cover!).

With that said, I don't understand how either of these makes a difference when saving a transient entity with a collection that contains ONE other transient entity -- all in the same session! If someone could clear that up, I'd be most grateful. The ramifications of mixing entities from different sessions in the same Set are clear (to me).

-Chris


Top
 Profile  
 
 Post subject: Still not solved!
PostPosted: Mon May 16, 2005 10:44 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
I have implemented .equals() and .hashCode() two different ways; checking the primary key only (not really what we want), and also checking business equality (using all non-PK fields). Both are listed below, and neither solves the phantom join table insert.

I still do not understand why equals/hashCode come in to play with SINGLE SESSION inserts of a Set containing ONE ENTITY. If I understood this issue, perhaps I'd be able to diagnose the problem more thoroughly on my end. This is looking more and more like a bug.

The utility methods used are from this page: http://www.javapractices.com/Topic28.cjp

-Chris

eq/hc using PK only:

Code:
    public boolean equals(Object that) {
        if (this == that) return true;
        if (!(that instanceof Address)) return false;
        Address thatAddress = (Address) that;
        if (this.getId() == null || thatAddress.getId() == null) {
            return false;
        } else {
            return this.getId().equals(thatAddress.getId());
        }
    }

    public int hashCode() {
        int hashCode = HashCodeUtils.SEED;
        hashCode = HashCodeUtils.hash(hashCode, getId());
        return hashCode;
    }


eq/hc using non-PK fields:

Code:
    public boolean equals(Object that) {
        if (this == that) return true;
        if (!(that instanceof Address)) return false;
        Address thatAddress = (Address) that;
        return (this.hasEqualState(thatAddress));
    }

    public int hashCode() {
        int hashCode = HashCodeUtils.SEED;
        hashCode = HashCodeUtils.hash(hashCode, getDescription());
        hashCode = HashCodeUtils.hash(hashCode, getStreet1());
        hashCode = HashCodeUtils.hash(hashCode, getStreet2());
        hashCode = HashCodeUtils.hash(hashCode, getCity());
        hashCode = HashCodeUtils.hash(hashCode, getState());
        hashCode = HashCodeUtils.hash(hashCode, getPostalCode());
        hashCode = HashCodeUtils.hash(hashCode, getFirstName());
        hashCode = HashCodeUtils.hash(hashCode, getMiddleName());
        hashCode = HashCodeUtils.hash(hashCode, getLastName());
        hashCode = HashCodeUtils.hash(hashCode, getNationalId());
        hashCode = HashCodeUtils.hash(hashCode, getRegionId());
        hashCode = HashCodeUtils.hash(hashCode, getCountry());
        hashCode = HashCodeUtils.hash(hashCode, getPhone());
        return hashCode;
    }


Top
 Profile  
 
 Post subject: Solved? I have no idea.
PostPosted: Mon May 16, 2005 2:01 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Well, with no changes, and a complete recompile, both examples above now work. I give up. I don't understand it, but it works. Go figure.


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