-->
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: Hibernate's Delete Method giving StaleStateException
PostPosted: Tue Jan 18, 2011 9:45 am 
Beginner
Beginner

Joined: Mon Sep 20, 2010 2:35 am
Posts: 20
Hi All,

I am trying to delete object using Hibernate's delete method but getting StaleStateException exception.My requirement is to delete an object based on the unique key so for this i am doing something like.
Code:
String queryString="from Destination destination "+
                                                   "where destination.destinationID = :destinationid";
    tx.begin();
                Query query= session.createQuery(queryString).setParameter("destinationid", destinationId, Hibernate.STRING);
               @SuppressWarnings("unchecked")
               List<Destination> list=query.list();
             
                 if(!list.isEmpty()){
                  Destination ds=list.get(0);
                 session.evict(ds);
                  session.delete(ds);
                }
                  tx.commit();



since i know there will be only one element in the list if its not empty so only fetching the first element from the list (Not sure if this is a good approach)

but when i am running this method i can see the following sql log in my console

Code:
Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection AirTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection RoadTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete collection TrainTransport.timeTable */ delete
        from
            tr.TRANSPORTTIME
        where
            TRANSPORTID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete AirTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?
Hibernate:
    /* delete RoadTransport */ delete
        from
            tr.TRANSPORT
        where
            UUID=?



and than its throwing
Code:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)


one thing which making me suspicious is that in my Transport table i have three entries only one for AirTransport one for Train and last one for Road and in the TransPortTime table i have three entries one for each Transport type and

i am using TransportTime as composite-element in side all three transport classes
Code:
<set name="timeTable" table="TRANSPORTTIME" lazy="true">
                        <key column="TRANSPORTID"/>
                        <composite-element
                                class="TransportTime">

                                <property name="deperatureTime" type="java.util.Date">
                                        <column name="DEPERATURETIME" />
                                </property>
                                <property name="arrivalTime" type="java.util.Date">
                                        <column name="ARRIVALTIME" />
                                </property>
                                <other properties>
                        </composite-element>

                </set>


i am still unable to figure out whats going wrong so though of asking in the community

[Update1]
Just to add some extra information: i have the below mapping in my destination class for the three respective trabsport classes
Code:
<set name="airTransport" table="AIRTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="AirTransport" />
    </set>
    <set name="roadTransport" table="ROADTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="RoadTransport" />
    </set>
    <set name="trainTransport" table="TRAINTRANSPORT" inverse="true" lazy="true" cascade="save-update, delete">
        <key>
            <column name="DESTINATIONID" />
        </key>
        <one-to-many class="TrainTransport" />
    </set>



and in my RoadTransport/Train/Air Transport have following mapping
Code:
<class name="AirTransport" table="TRANSPORT">
        <id name="uuid" type="java.lang.String">
            <column name="UUID" />
            <generator class="uuid"/>
        </id>
        <many-to-one name="destination" class="Destination" fetch="join">
            <column name="DESTINATIONID" />
        </many-to-one>
       <property mappings>
        <set name="timeTable" table="TRANSPORTTIME" lazy="true">
            <key column="TRANSPORTID"/>
            <composite-element
                class="TransportTime">
                <property mappings>
                </composite-element>

        </set>
    </class>



Other two mapping files are also identical so when i removed mapping association of these three classes from parent class my delete functionality started working perfectly.
So this means i am doing fundamenally wrong in mapping the TimeTable class as component inside Transport classes (Air/Train/Road Transport class)
any suggestion in this regard will be much helpfull

thanks in advance


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.