-->
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: Row was updated or deleted by another transaction
PostPosted: Thu Feb 22, 2007 10:18 am 
Newbie

Joined: Wed Feb 15, 2006 8:40 am
Posts: 7
Hallo,

ich habe ein Problem bei einem XML-Importer. Es soll ein XML File eingelesen werden. Daraus werden dann die Objekte befüllt und in die Datenbank mit Hibernate gespeichert.

Die IDs sind aus einer Sequence und die Objekte sind immer alle neu. Es gibt also keinen Grund für Hibernate hier ein Update durchzuführen, da es alle Objekte noch nicht gibt.

Nun tritt jedoch seit ein paar Tagen die unten geschriebene Exception auf, und ich habe keinen Ansatz, woran es liegen könnte.

Hier in den Foren findet man die Exception immer im Zusammenhang mit versioning bzw timestamp. Ich habe jedoch keine dieser Angaben in meinem Mapping gemacht.

Sollten noch weitere Mappings und Angaben benötigt werden, bitte Bescheid geben :-)

Vielen Dank und viele Grüße,
Andi

Hibernate version:
3.0

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 default-lazy="false"
>
    <class
        name="com.indatex.data.message.MessageBody"
        table="messagebody"
        polymorphism="implicit"
    >

        <id
            name="id"
            column="id"
            type="long"
        >
            <generator class="sequence">
                <param name="sequence">webEDI_sequence</param>
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-MessageBody.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-MessageBody.xml
            containing the additional properties and place it in your merge dir.
        -->

        <joined-subclass
            name="com.indatex.data.message.LABMessageBody"
            table="lab_messagebody"
        >
            <key
                column="id"
            />

        <many-to-one
            name="documentInformation"
            class="com.indatex.data.message.DocumentInformation"
            cascade="all"
            outer-join="auto"
            update="true"
            insert="true"
            column="document_information_id"
            unique="true"
        />

        <many-to-one
            name="footer"
            class="com.indatex.data.message.Footer"
            cascade="all"
            outer-join="auto"
            update="true"
            insert="true"
            column="footer_id"
            unique="true"
        />

        <set
            name="positionSet"
            lazy="false"
            cascade="all"
            sort="unsorted"
        >

            <key
                column="message_body_id"
            >
            </key>

            <one-to-many
                  class="com.indatex.data.message.Positions"
            />

        </set>

        </joined-subclass>

    </class>

</hibernate-mapping>


Klassen die zum Mapping gehören:

Code:
package com.indatex.data.message;

import java.util.Set;

/**
* @hibernate.joined-subclass table="lab_messagebody"
* @hibernate.joined-subclass-key column="id"
*/
public class LABMessageBody extends MessageBody {

  private DocumentInformation documentInformation;
  private Set positionSet;  // a set of positions
  private Footer footer;

  /**
   * @hibernate.many-to-one column="document_information_id" unique="true" cascade="all"
   */
  public DocumentInformation getDocumentInformation() {
    return documentInformation;
  }

  public void setDocumentInformation(DocumentInformation documentInformation) {
    this.documentInformation = documentInformation;
  }

  /**
   * @hibernate.many-to-one column="footer_id" unique="true" cascade="all"
   */
  public Footer getFooter() {
    return footer;
  }

  public void setFooter(Footer footer) {
    this.footer = footer;
  }

  /**
   * @hibernate.set cascade="all"
   * @hibernate.collection-key column="message_body_id"
   * @hibernate.collection-one-to-many class="com.indatex.data.message.Positions"
   */
  public Set getPositionSet() {
     return positionSet;
   }


   public void setPositionSet(Set positionSet) {
     this.positionSet = positionSet;
   }

}


Code:
/**
* $Header: /export/cvsroot/webEDI/src/com/indatex/data/message/MessageBody.java,v 1.7 2006/03/08 15:20:19 abi Exp $
*/
package com.indatex.data.message;


import com.indatex.data.message.interfaces.IMessageBody;

/**
* @hibernate.class table="messagebody" polymorphism="implicit"
*/
public abstract class MessageBody implements IMessageBody {

  private Long id;

  /**
   * Returns the object id
   *
   * @hibernate.id column="id" generator-class="sequence" type="long"
   * @hibernate.generator-param name="sequence" value="webEDI_sequence"
   * @return object id
   */
  public Long getId() {
    return id;
  }

  /**
   * Sets the object id
   *
   * @param id
   *          object id
   */
  public void setId(Long id) {
    this.id = id;
  }

}


Methode in die Speicherung stattfindet (gekürzt):
Code:
    /**
     * parse the xml-file, collect the values for the different object and build
     * a message-header object
     */
    public void parseXML() {

        // ...
        // Variablen Intitialisierung
        // ...

        try {
                int size = this.xmlFiles.size();

                for (int i = 0; i < size; i++) {
                    logger.info("\tFile-#: " + (i + 1));

                    // ...
                    // einlesen der Daten und Befuellen der
                    // Objekte
                    // ...

                    // after parsing insert the different objects to the
                    // messageheader
                    boolean messageStored = false;
                   
                    // ...
                    this.senderlocation.setKeyValuesPairs(this.valuePairsSender);
                    this.sender.setLocation(this.senderlocation);
                    this.receiverLocation
                                .setKeyValuesPairs(this.valuePairsReceiver);
                    this.receiver.setLocation(this.receiverLocation);
                    this.messageHeader
                                .setFileAttachements(this.attachementBuffer);
                    this.messageHeader.setSender(this.sender);
                    this.messageHeader.setSystemDetails(this.systemDetails);
                    this.messageHeader.setReceiver(this.receiver);
                    this.messageHeader
                                .setSubjectNumbers(this.subjectNumberItemSet);
                    this.messageHeader.setOrderInfo(this.orderInfo);
                    this.messageHeader
                                .setMessageState(CMessageClassification.messageState_NEW);

                    this.message.setMessageHeader(this.messageHeader);
                    this.message.setMessageBody(this.messageBody);


                    // ...
                    // Hier kommt nun die vermeintlich problematische Klasse.
                    // Der darunterliegende Objektbaum ist schon gefüllt.

                    LABMessageBody body = (LABMessageBody) this.messageBody;
                    InstructionInformation instructionInformation = body
                                    .getDocumentInformation()
                                    .getInstructionInformation();
                    Service service = instructionInformation
                                    .getService();
                    String orderId = Order.getOrderId(service);
                    Order order = orderDAO.getOrderByOrderId(orderId);
                    if (order == null) {
                            order = new Order();
                            order.setOrderId(orderId);
                            order.setMessages(new ArrayList());
                     }

                     logger.info("Store imported message in database");
                     messageDAO.storeMessage(message);

                     ////////////////////////////////////////////////////////////////////////
                     // HIER KNALLT ES                                                     //
                     ////////////////////////////////////////////////////////////////////////
                     orderDAO.flush();

                     order.getMessageIds().add(this.message.getId());
                     order.setCurrentServiceDemandType(service
                                    .getServiceDemandType());
                     order
                                    .setCurrentInstructionType(instructionInformation
                                            .getInstructionType());
                     logger.info("Store order in database");
                     orderDAO.storeOrder(order);
                     orderDAO.flush();
                     messageStored = true;

                     // write message in database
                     if (!messageStored) {
                         messageDAO.storeMessage(message);
                         orderDAO.flush();
                     }

                    // ...
                    // Dateibehandlungen
                    // ...
                }

            } catch (JDOMParseException e) {
                logger.error("ParseException in Line(" + e.getLineNumber()
                        + ") Column(" + e.getColumnNumber() + ")", e);
            } catch (Exception e) {
                logger.error("Exception", e);
                throw new RuntimeException("error inserting data", e);
            }
    }


Full stack trace of any exception that occurs:
org.hibernate.event.def.AbstractFlushingEventListener: Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.indatex.data.message.LABMessageBody#33299]
at org.hibernate.persister.entity.BasicEntityPersister.check(BasicEntityPersister.java:1441)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:1986)
at org.hibernate.persister.entity.BasicEntityPersister.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersister.update(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:75)
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:137)
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.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:788)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:786)
at com.indatex.data.message.dao.hibernate.vwl.HibernateOrderDAO.flush(HibernateOrderDAO.java:80)
at sun.reflect.GeneratedMethodAccessor1462.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at com.indatex.util.logging.TracingMethodInvocation.invoke(TracingMethodInvocation.java:20)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy73.flush(Unknown Source)
at com.indatex.data.xml.XMLImporter.parseXML(XMLImporter.java:393)
at com.indatex.bussiness.xml.XMLBusiness.importXML(XMLBusiness.java:74)
at sun.reflect.GeneratedMethodAccessor1303.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:292)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy82.importXML(Unknown Source)
at com.indatex.scheduler.XMLImportJob.executeInternal(XMLImportJob.java:24)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:66)
at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:516)

Name and version of the database you are using:
Oracle 10g


Last edited by frosch95 on Thu Feb 22, 2007 12:14 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 11:06 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Klasse vielleicht posten

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 12:17 pm 
Newbie

Joined: Wed Feb 15, 2006 8:40 am
Posts: 7
Ich habe die Datenklassen, sowie die Methode in der die Speicherung stattfindet, in dem ursprünglichen Beitrag gepostet. Werden sonst noch Klassen benötigt?

Vielen Dank für die Hilfe,
Andi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 1:15 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Vermutung
a) Du setzt versehentlich die id auf 0
b) Du verwendest den MessageBody mehrfach, anstatt ihn neu zu instanzieren
c) es gibt mehrere MessageBody pro Order

Ich würde mir die ID vor dem Speichern ausgeben lassen.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 1:44 pm 
Newbie

Joined: Wed Feb 15, 2006 8:40 am
Posts: 7
Danke,
ich werde eine entsprechende Log Ausgabe einbauen.

a) die ID kommt ja aus eine Sequenz und um das setzen kümmert sich ja eiegentlich Hibernate, aber ich lass das zur Sicherheit trotzdem mal ausgeben.

b) kann ich ausschliessen, denn vor jedem Durchlauf wird
this.messageHeader = new MessageHeader();
gemacht.

c) Order und Message sind sehr lose gekoppelt. In Order werden
nur die IDs der Message Objekte abgelegt. Aber es wird keine Referenz
angelegt.

Aber da trotz aller Vorsicht und Durchsicht des Codes eventuell das ein oder andere als Nebeneffekt auftreten kann, werde ich einfach versuchen alle drei Fälle mit Hilfe von logging statements zu verifizieren.

Vielen Dank nochmal.
Gruß,
Andi


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.