-->
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.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Exception while deleting parent object
PostPosted: Thu Feb 19, 2004 7:00 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 4:59 am
Posts: 23
Here are my mappings

PARENT OBJECT
<hibernate-mapping>
<class name="objects.Parent" table="PARENT">
<id name="parent_id" type="int" column="PARENT_ID">
<generator class="identity"/>
</id>
<property name="title" type="string">
<column name="TITLE" sql-type="TEXT" not-null="true"/>
</property>
<set name="children" table="CHILD" sort="comparators.ChildComparator" cascade="all-delete-orphan">
<key>
<column name="PARENT_ID"/>
</key>
<one-to-many class="objects.Child"/>
</set>
</class>
</hibernate-mapping>

CHILD OBJECT
<hibernate-mapping>
<class name="objects.Child" table="CHILD">
<composite-id name="child_pk" class="objects.ChildPK">
<key-property name="child_id" column="CHILD_ID" type="int"/>
<key-many-to-one name="parent" class="objects.Parent">
<column name="PARENT_ID"/>
</key-many-to-one>
</composite-id>
<property name="text" type="string">
<column name="TEXT" sql-type="TEXT" not-null="false"/>
</property>
</class>
</hibernate-mapping>


CODE TO EXECUTE
Session sess = HibernateUtil.currentSession();
sess.delete(parent);
sess.flush();
HibernateUtil.closeSession();

STUPID EXCEPTION

13:50:07,562 ERROR SessionImpl:2269 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:118)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:55)
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:105)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.jav
a:565)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2266)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at com.overalltesting.servlets.DeleteParent.doGet(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet
.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246
)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:
164)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:534)


COMMENT
I see this exception if there are more than 0 child objects for current parent.
Any ideas ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:08 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
inverse="true" on the collection, read the wiki page talking about that.
and batch_size=0 to have a more fine grained error

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:11 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 4:59 am
Posts: 23
emmanuel wrote:
inverse="true" on the collection, read the wiki page talking about that.
and batch_size=0 to have a more fine grained error


More description ? Maybe URL to wiki page ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
http://www.hibernate.org/155.html and http://www.hibernate.org/hib_docs/reference/html/parent-child.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:28 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 4:59 am
Posts: 23
the same exception !
inverse="true" didn't help !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Look at the log and the generated SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:50 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 4:59 am
Posts: 23
gloeglm wrote:
Look at the log and the generated SQL.


14:48:56,890 DEBUG SQL:223 - update CHILD set PARENT_ID=null where PARENT_ID=?
14:48:56,906 DEBUG SQL:223 - delete from CHILD where CHILD_ID=? and PARENT_ID=?
EXCEPTION

Damn, where is that update from ? and why null... ???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 8:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Keep inverse="true" on the set.
Show the full code (parent retrieve by load() and parent deletion) in a simple test case and the associated logs.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 10:02 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 4:59 am
Posts: 23
emmanuel wrote:
Keep inverse="true" on the set.
Show the full code (parent retrieve by load() and parent deletion) in a simple test case and the associated logs.


Full code
Code:
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Parent parent = (Parent)session.load(Parent.class, new Integer(parent_id));
tx.commit();
HibernateUtil.closeSession();

then:
Code:
Session sess = HibernateUtil.currentSession();
sess.delete(parent);
sess.flush();
HibernateUtil.closeSession();


That is all !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 12:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It should work with inverse="true", Hibernate may be swindled by the <key-many-to-one> instead of <many-to-one not-null="true">

Please submit a bug to JIRA

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 2:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, <key-many-to-one> is no problem.

I assume that the user has not followed your instruction to add inverse="true".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2004 8:00 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 4:59 am
Posts: 23
gavin wrote:
No, <key-many-to-one> is no problem.

I assume that the user has not followed your instruction to add inverse="true".


Here is the final variant of Parent object (NOT WORKING):

<hibernate-mapping>
<class name="objects.Parent" table="PARENT">
<composite-id name="parent_pk" class="objects.ParentPK">
<key-property name="parent_id" column="PARENT_ID" type="int"/>
<key-many-to-one name="GRAND_PARENT" class="objects.GrandParent">
<column name="GRANDPARENT_ID"/>
</key-many-to-one>
</composite-id>
<property name="text" type="string">
<column name="TEXT" sql-type="TEXT" not-null="false"/>
</property>
<set name="children" table="CHILD" sort="comparators.ChildComparator" inverse="true" cascade="all-delete-orphan">
<key>
<column name="GRANDPARENT_ID"/>
<column name="PARENT_ID"/>
</key>
<one-to-many class="objects.Child"/>
</set>
</class>
</hibernate-mapping>

Maybe it's not working because of 2-level relationships ???
GrandParent has 0 or more Parent objects, and Parent object may has 0 or more Child objects ! Exception, while deleting Parent object !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 4:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the child mapping.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 9:10 am 
Beginner
Beginner

Joined: Thu Feb 05, 2004 4:59 am
Posts: 23
emmanuel wrote:
Show the child mapping.


CHILD MAPPING

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="objects.Child" table="CHILD">
<composite-id name="child_pk" class="objects.ChildPK">
<key-property name="child_id" column="CHILD_ID" type="int"/>
<key-many-to-one name="parent" class="objects.Parent">
<column name="GRANDPARENT_ID"/>
<column name="PARENT_ID"/>
</key-many-to-one>
</composite-id>
<property name="text" type="string">
<column name="TEXT" sql-type="TEXT" not-null="false"/>
</property>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 9:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I feel usafe with
delete from CHILD where CHILD_ID=? and PARENT_ID=?
It should have been the GRAND_PARENT_Id olumn. I don't know why it's not in.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

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.