-->
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: Transitive ManyToMany Collection Problem(s)
PostPosted: Mon Jan 15, 2007 4:32 pm 
Newbie

Joined: Mon Jan 15, 2007 3:22 pm
Posts: 6
Hibernate version:
Annotations 3.2.0.CR1 + compatible Hibernate (3.2.1CR4?)

The system I am building has 40 persistent types with many different kinds of relationships. I have been wrestling with a problem for some time: I am having trouble with a transitive ManyToMany collection - it is probably my lack of understanding of one of the subtler aspects of Hibernate so a little help and guidance would be appreciated.

The broad overview of this section is roughly:

MonsterObject -> ObjectCollection -> GameObject
monster -> contents -> it's stuff
A MonsterObject (a derived class from GameObject) holds a collection of other GameObjects (it's "inventory")

The definition for the contents collection within the MonsterObject class is:
@ManyToMany ( fetch=FetchType.EAGER, cascade = { CascadeType.ALL} )
@JoinTable ( name="collection_objs" )
public List<GameObject> getContents() {

#1) When the MonsterObject is deleted(), it's contents should also be deleted(), so the collection is marked CascadeType.ALL. However, when the delete() happens I get an exception:

org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)

at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)

This suggests that an object that has already been deleted is being deleted again. However, from looking at the data, this is not the case unless one of the contained object in this collection is being deleted twice. GameObjects without contained objects delete fine so this collection is the culprit. What I'd like to know is is there another interpretation for this exception?

#2) Interestingly (and perhaps unrelatedly), if I change the definition for this collection to:

@ManyToMany ( fetch=FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE } )
@JoinTable ( name="collection_objs" )
public List<GameObject> getContents() {

I get a TransientObjectException trying to persist the MonsterObject instead - does this cascade definition not indicate the contents of the collection should be transitively persisted? I have been working with this version of Hibernate for some months and have noticed that if you change from CascadeType.ALL to any other setting, transitive persistence is often lost. Is this the expected behaviour i.e. there is more to CascadeType.ALL than just { CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE, CascadeType.REMOVE } ?

Thanks,
Matt


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.