-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate won't leave my many-to-many alone
PostPosted: Wed Feb 01, 2006 1:04 am 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
Hibernate version:3.1

Name and version of the database you are using:SQL 2000


Example:

Owner -> Cats -> Toys

Owner -> Cats: one-to-many

Cats -> Toys: many-to-many (via a view)

If I load an Owner and clear() its collection of cats, then flush, Hibernate tries to delete each cat’s collection of toys, and fails because the many-to-many is based on a view. I do not touch the toys collection at all. I have set optimistic lock to false, set mutable to false, set cascade to ‘none’ on that toys collection. Nothing seems to change this behavior. I don’t want Hibernate to attempt to modify anything in that many-to-many collection. Any ideas?

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 2:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why do you clear() the collection in the first place ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 5:06 am 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
This is a web-base system where the user is puttting in information via an html form. So, using this example, let's say the user enters an owner and multiple cats (in a single form submission). Then later, goes back to update (add/remove cats from the collection).
So, what I do is load the persisted object (this is an update) and copy in the new property values from the submitted form. For the collection, rather than trying to figure out which cats are new, which ones have been removed from the collection by the user, I'd rather just clear the old collection, and re-populate it with the new collection objects. So I issue a clear() on that cats collection, then populate it with new objects. So, in other words, for the collection items, it's turns into more of a delete/insert for those objects.
Does that make sense?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 5:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no not really ;) why do you want to map something that you don't want to be persistent ?

why don't you just query for the relavant data instead of mapping it as a collection ?

If you absolutly want to map this as a collection then copy the needed data in the setter to another collection which you then can use for you manipulation...but i would definitly go for the option of querying for the data instead of map it as a collection.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 12:16 am 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
Quote:
why do you want to map something that you don't want to be persistent ?

The collection items are persisted, they're just not persisted from that collection... the collection in question is basically a subset of another collection where they are persisted.


Quote:
why don't you just query for the relavant data instead of mapping it as a collection ?

Because it's simpler (and more robust I think) to simply access a collection throughout my application than maintaining a bunch of queries everywhere. And I have other non-hibernate requirements to use that view as well.

Anyway, if you're telling me Hibernate doesn't want me to map collections that won't be persisted from that collection, then that's fine, I'll just try to stay away from doing that.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 03, 2006 2:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well hibernate will stay away from it if you don't mess with the collection.

inverse=true might also help.

but otherwise map the persistent collection to something else and copy it over to the collection you want to manipulate.

_________________
Max
Don't forget to rate


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