-->
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: Saving one-to-many relationship fails
PostPosted: Fri Jul 01, 2005 2:01 pm 
Newbie

Joined: Thu Jan 29, 2004 9:05 am
Posts: 3
Location: Estonia
Hi.

I have one-to-many relationship mapped as Set. When performing cascade save, I get error: Could not synchronize database state with session. SQL insert, update or delete failed (row not found). However, all insert and update statements made by Hibernate look OK (all statement parameters are OK too).

One complicating matter is that for accessing Hibernate, I use fairly complex (and quite clumsy) framework for accessing Hibernate sessions. However, this framework apparently works in other projects and this error occurs in single Session.save() method call, so that mechanics of acquiring session instance should not matter too much.

I am using Hibernate inside stateless session beans with container-managed transactions. In previous messages, this kind of problem has been solved by setting correct unsaved-value for identifier. I am using java.lang.Long as identifier and it's automatically generated (not assigned).

Hibernate version: 2.1.6

Mapping documents:

SadDocument.hbm.xml

Code:
<?xml version="2.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="ee.fin.icis.complex.processor.model.SadDocument"
      table="SAD_DOCUMENT"
      dynamic-update="false" dynamic-insert="false"
      lazy="true" discriminator-value="null">
      <id name="id" column="id" type="java.lang.Long" unsaved-value="null" access="field">
         <generator class="sequence">
            <param name="sequence">SAD_DOCUMENT_ID</param>
         </generator>
      </id>

      <version name="sysVersion" type="java.lang.Long" column="sys_version"/>
      
      <property name="declarationType" type="java.lang.String" length="30" column="declarationType" access="field"/>
      <property name="declarationMode" type="java.lang.String" length="30" column="declarationMode" access="field"/>
      <property name="referenceNumber" type="java.lang.String"
         column="referenceNumber" not-null="false"  access="field"/>
      <property name="acceptanceNumber" type="java.lang.String"
         column="acceptanceNumber" not-null="false"  access="field"/>
      <property name="processingDate" type="java.util.Date"
         column="processingDate" not-null="false"  access="field"/>
      <property name="acceptanceDate" type="java.util.Date"
         column="acceptanceDate" not-null="false"  access="field"/>
      <set name="sadVersions" lazy="true" batch-size="20"
         cascade="all-delete-orphan" sort="unsorted" access="field">
         <key column="sad_document_id"/>
         <one-to-many class="ee.fin.icis.complex.processor.model.SadVersion"/>
      </set>
      <set name="statuses" lazy="true" batch-size="20"
         cascade="all-delete-orphan" sort="unsorted" access="field">
         <key column="sad_document_id"/>
         <one-to-many class="ee.fin.icis.complex.processor.model.SadStatusChange"/>
      </set>   
   </class>
</hibernate-mapping>


SadStatusChange.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="ee.fin.icis.complex.processor.model.SadStatusChange"
      table="SAD_STATUS_CHANGE"
      dynamic-update="false" dynamic-insert="false"
      lazy="true" discriminator-value="null">
      <id name="id" column="id" type="java.lang.Long" unsaved-value="null" access="field">
         <generator class="sequence">
            <param name="sequence">SAD_STATUS_CHANGE_ID</param>
         </generator>
      </id>

      <version name="sysVersion" type="java.lang.Long" column="sys_version"/>
      
      <property name="newStatus" type="java.lang.String" length="30" column="newStatus" access="field"/>
      <property name="statusChangePerson" type="java.lang.String"
         column="statusChangePerson" not-null="false"  access="field"/>
      <property name="changeDate" type="java.util.Date"
         column="changeDate" not-null="false"  access="field"/>   
   </class>
</hibernate-mapping>


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

Code that triggers failure:

Code:
        SadDocument doc = new SadDocument();
        doc.setAcceptanceNumber("SOMETHING");
        SadStatusChange change = new SadStatusChange();
        change.setChangeDate(new Date());
        change.setNewStatus(SadStatus.STOPPED_DIVIDING);
        change.setStatusChangePerson("TODO!");
        doc.getStatuses().add(change);
        HibernateHelper.getHibernateTemplate().save(this);


SadDocument.java

Code:
/* GENERATED */

package ee.fin.icis.complex.processor.model;

/** SadDocument database class. */
public class SadDocument extends ee.fin.icis.common.data.ABaseModelBean
implements ee.fin.icis.common.data.Identity {

    private String declarationType;
    private String declarationMode;
    private String referenceNumber;
    private String acceptanceNumber;
    private java.util.Date processingDate;
    private java.util.Date acceptanceDate;
    private java.util.Set sadVersions;
    private java.util.Set statuses;

    private Long id;

    /** Gets id field value.
    * @return Id field value.
    */
    public Long getId() {
        return id;
    }

    /** Sets id field value.
    * @param id New value for the id field.
    */
    public void setId(Long id) {
        this.id = id;
    }

    /* Setters and getters */
    ...

    /** Gets statuses field value.
    * @return Statuses field value.
    */
    public java.util.Set getStatuses() {
        if (statuses == null) {
            statuses = new java.util.HashSet();
        }
        return statuses;
    }

    /** Sets statuses field value.
    * @param statuses New value for the statuses field.
    */
    public void setStatuses(java.util.Set statuses) {
        this.statuses = statuses;
    }
   
}



SadStatusChange.java

Code:
/* GENERATED */

package ee.fin.icis.complex.processor.model;

/** SadStatusChange database class. */
public class SadStatusChange extends ee.fin.icis.common.data.ABaseModelBean
implements ee.fin.icis.common.data.Identity {
    private String newStatus;
    private String statusChangePerson;
    private java.util.Date changeDate;

    private Long id;

    /** Gets id field value.
    * @return Id field value.
    */
    public Long getId() {
        return id;
    }

    /** Sets id field value.
    * @param id New value for the id field.
    */
    public void setId(Long id) {
        this.id = id;
    }

    /* Setters and getters */
    ...

}



Full stack trace of any exception that occurs:

Quote:
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:524)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2375)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.jca.JCASessionImpl.flush(JCASessionImpl.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at weblogic.connector.common.internal.ConnectionWrapper.invoke(ConnectionWrapper.java:149)
at $Proxy11.flush(Unknown Source)
at ee.fin.onion3.dao.hibernate.HibernateTemplate.execute(HibernateTemplate.java:136)
at ee.fin.onion3.dao.hibernate.HibernateTemplate.execute(HibernateTemplate.java:107)
at ee.fin.onion3.dao.hibernate.HibernateTemplate.save(HibernateTemplate.java:325)
at ee.fin.icis.complex.processor.model.SadDocument.save(SadDocument.java:33)
at ee.fin.icis.complex.processor.service.impl.business.declarationaccept.AssessDeclaration.run(AssessDeclaration.java:43)
at ee.fin.icis.complex.processor.service.impl.business.DeclarationAcceptServiceBO.assessDeclaration(DeclarationAcceptServiceBO.java:45)
at ee.fin.icis.complex.processor.service.impl.ejb.DeclarationAcceptServiceBean.assessDeclaration(DeclarationAcceptServiceBean.java:53)
at ee.fin.icis.complex.processor.service.impl.ejb.DeclarationAcceptService_ps9z0q_EOImpl.assessDeclaration(DeclarationAcceptService_ps9z0q_EOImpl.java:370)
at ee.fin.icis.complex.processor.service.impl.ejb.DeclarationAcceptService_ps9z0q_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:415)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)


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

Debug level Hibernate log excerpt:

Quote:
DEBUG getConnection called with subject[null ] connection request info[null]
DEBUG opened session
DEBUG Added session handle - net.sf.hibernate.jca.JCASessionImpl@25a091 to handles now at size 1
DEBUG about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG select SAD_DOCUMENT_ID.nextval from dual
Hibernate: select SAD_DOCUMENT_ID.nextval from dual
DEBUG preparing statement
DEBUG Sequence identifier generated: 12
DEBUG done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG closing statement
DEBUG generated identifier: 12
DEBUG saving [ee.fin.icis.complex.processor.model.SadDocument#12]
DEBUG processing cascades for: ee.fin.icis.complex.processor.model.SadDocument
DEBUG done processing cascades for: ee.fin.icis.complex.processor.model.SadDocument
DEBUG Seeding: 0
DEBUG Wrapped collection in role: ee.fin.icis.complex.processor.model.SadDocument.statuses
DEBUG processing cascades for: ee.fin.icis.complex.processor.model.SadDocument
DEBUG cascading to collection: ee.fin.icis.complex.processor.model.SadDocument.statuses
DEBUG cascading to saveOrUpdate()
DEBUG saveOrUpdate() unsaved instance
DEBUG about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG select SAD_STATUS_CHANGE_ID.nextval from dual
Hibernate: select SAD_STATUS_CHANGE_ID.nextval from dual
DEBUG preparing statement
DEBUG Sequence identifier generated: 12
DEBUG done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG closing statement
DEBUG generated identifier: 12
DEBUG saving [ee.fin.icis.complex.processor.model.SadStatusChange#12]
DEBUG Seeding: 0
DEBUG done processing cascades for: ee.fin.icis.complex.processor.model.SadDocument
DEBUG flushing session
DEBUG processing cascades for: ee.fin.icis.complex.processor.model.SadDocument
DEBUG cascading to collection: ee.fin.icis.complex.processor.model.SadDocument.statuses
DEBUG cascading to saveOrUpdate()
DEBUG saveOrUpdate() persistent instance
DEBUG done processing cascades for: ee.fin.icis.complex.processor.model.SadDocument
DEBUG Flushing entities and processing referenced collections
DEBUG Collection found: [ee.fin.icis.complex.processor.model.SadDocument.statuses#12], was: [<unreferenced>]
DEBUG Processing unreferenced collections
DEBUG Scheduling collection removes/(re)creates/updates
DEBUG Flushed: 2 insertions, 0 updates, 0 deletions to 2 objects
DEBUG Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
DEBUG listing entities:
DEBUG ee.fin.icis.complex.processor.model.SadDocument{referenceNumber=null, statuses=[SadStatusChange#12], processingDate=null, declarationMode=null, declarationType=null, sadVersions=null, acceptanceNumber=SOMETHING, sysVersion=0, id=12, acceptanceDate=null}
DEBUG ee.fin.icis.complex.processor.model.SadStatusChange{statusChangePerson=TODO!, newStatus=STOPPED_DIVIDING, changeDate=2005-07-01 20:31:37, sysVersion=0, id=12}
DEBUG executing flush
DEBUG Inserting entity: [ee.fin.icis.complex.processor.model.SadDocument#12]
DEBUG Version: 0
DEBUG about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG insert into SAD_DOCUMENT (sys_version, declarationType, declarationMode, referenceNumber, acceptanceNumber, processingDate, acceptanceDate, id) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into SAD_DOCUMENT (sys_version, declarationType, declarationMode, referenceNumber, acceptanceNumber, processingDate, acceptanceDate, id) values (?, ?, ?, ?, ?, ?, ?, ?)
DEBUG preparing statement
DEBUG Dehydrating entity: [ee.fin.icis.complex.processor.model.SadDocument#12]
DEBUG binding '0' to parameter: 1
DEBUG binding null to parameter: 2
DEBUG binding null to parameter: 3
DEBUG binding null to parameter: 4
DEBUG binding 'SOMETHING' to parameter: 5
DEBUG binding null to parameter: 6
DEBUG binding null to parameter: 7
DEBUG binding '12' to parameter: 8
DEBUG Inserting entity: [ee.fin.icis.complex.processor.model.SadStatusChange#12]
DEBUG Version: 0
DEBUG done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG closing statement
DEBUG about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG insert into SAD_STATUS_CHANGE (sys_version, newStatus, statusChangePerson, changeDate, id) values (?, ?, ?, ?, ?)
Hibernate: insert into SAD_STATUS_CHANGE (sys_version, newStatus, statusChangePerson, changeDate, id) values (?, ?, ?, ?, ?)
DEBUG preparing statement
DEBUG Dehydrating entity: [ee.fin.icis.complex.processor.model.SadStatusChange#12]
DEBUG binding '0' to parameter: 1
DEBUG binding 'STOPPED_DIVIDING' to parameter: 2
DEBUG binding 'TODO!' to parameter: 3
DEBUG binding '2005-07-01 20:31:37' to parameter: 4
DEBUG binding '12' to parameter: 5
DEBUG done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG closing statement
DEBUG Inserting collection: [ee.fin.icis.complex.processor.model.SadDocument.statuses#12]
DEBUG about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG update SAD_STATUS_CHANGE set sad_document_id=? where id=?
Hibernate: update SAD_STATUS_CHANGE set sad_document_id=? where id=?
DEBUG preparing statement
DEBUG binding '12' to parameter: 1
DEBUG binding '12' to parameter: 2
ERROR Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
[/code]


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.