-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem Deleting from Set
PostPosted: Wed Sep 21, 2005 12:32 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
I have studied up on deleting objects in "Hibernate In Action" and it seems simple enough. Yet, I am having a few issues. Basically, what it boils down to is that I will remove a RegistrationSession object from a set inside a Registration object but when it comes time to update the Registration object the deleted RegistrationSession object in the set does not get deleted. It instead gets updated.

Do I need to make sure the object being delete does not have anything depending on it? Do all objects that it references need to be dereferenced or made null?

Nothing that I try seems to work. I have a feeling that it could be a setting somewhere in my mapping documents but not sure.

Any help greatly appreciated.

Cheers
Tom

Hibernate version: The one that ships with JBoss 4.0.3. I think its now version 3 but not sure.

Mapping documents:

Registration

<class name="com.camp.common.registration.Registration" table="tblRegistration">

<cache usage="read-write"/>

<id name="registrationID" type="integer">
<column name="id_registration" sql-type="integer" not-null="true"/>
<generator class="sequence">
<param name="sequence">tblregistration_id_registration_seq</param>
</generator>
</id>

<set name="regSessions" table="tblRegSession" sort="com.camp.common.registration.RegistrationSessionComparator" order-by="id_reg_session asc" cascade="all-delete-orphan" inverse="true">
<cache usage="read-write"/>
<key column="fk_id_registration"/>
<one-to-many class="com.camp.common.registration.RegistrationSession"/>
</set>

</class>

RegistrationSession

<class name="com.camp.common.registration.RegistrationSession" table="tblRegSession">

<cache usage="read-write"/>

<id name="regSessionID" type="integer">
<column name="id_reg_session" sql-type="integer" not-null="true"/>
<generator class="sequence">
<param name="sequence">tblregsession_id_reg_session_seq</param>
</generator>
</id>

<many-to-one name="registration" column="fk_id_registration" class="com.camp.common.registration.Registration" not-null="true"/>

<many-to-one name="cabin" column="fk_id_cabin" class="com.camp.common.cabin.Cabin" not-null="true"/>

<many-to-one name="session" column="fk_id_session" class="com.camp.common.session.Session" not-null="true"/>

</class>

Do I need to remove all references to registration, cabin and session?

Code between sessionFactory.openSession() and session.close():
This is the code that I originally had which I thought would work to delete the RegistrationSession but its not working.

reg_session = (RegistrationSession) registration.getRegistrationSession(i);
reg_session.setCabin(null);
reg_session.setSession(null);
regSessions.remove(reg_session);
hib_session.update(registration);

Full stack trace of any exception that occurs:

I think this error happens because I am manually trying to delete the RegistrationSession objects and then updating the Registration and thats when things go haywire!!

org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 1 actual row count: 0 expecte
d: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:28
4)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:736)
at com.camp.server.entity.EntityBackEnd.modifyEntities(Unknown Source)
at com.camp.helpers.entity.EntityHelper.modifyEntities(Unknown Source)
at com.camp.actions.registration.updateRegistrationSessionsAction.execute(Unknown Source)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:188)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.camp.common.utilities.HibernateFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

Name and version of the database you are using:
Postgres 8.0.4

The generated SQL (show_sql=true):
10:15:08,525 INFO [STDOUT] Hibernate: update tblRegSession set fk_id_registration=?, fk_id_cabin=?, fk_id_session=?, us
er_entered=? where id_reg_session=?
10:15:08,525 INFO [STDOUT] Hibernate: update tblRegSession set fk_id_registration=?, fk_id_cabin=?, fk_id_session=?, us
er_entered=? where id_reg_session=?


Top
 Profile  
 
 Post subject: Re: Problem Deleting from Set
PostPosted: Wed Sep 21, 2005 2:40 pm 
Beginner
Beginner

Joined: Wed Mar 16, 2005 4:07 pm
Posts: 22
i think you are getting a staleobjectexception, which means your object is out-of-date. you must be using optimistic locking. make sure the version number is the same as the one in db.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 2:44 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
Well, the StateObjectException happens because of my attempted workaround, so really I shouldn't have included it at all. The reason I get it is because I try to delete the RegistrationSession manually, and then at the end when I close the session the Registration gets updated which then tries to update the set, including the deleted object. Which causes the error.


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