-->
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.  [ 5 posts ] 
Author Message
 Post subject: Not cascaded OneToMany association gets refreshed on merge
PostPosted: Mon Mar 17, 2008 12:17 pm 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
I have a City with a bi-directional @OneToMany association to Person:

Code:
@OneToMany(mappedBy = "city")
@OptimisticLock(excluded = true) // No dirty checking
public List<Person> getPersons()


So there's no cascading.
However when I merge a detached City back into the persistent context, I see it refresh (= select) every detached Person of the detached city.
How can I avoid this?

It has 2 problems:
- It creates an n+1 query problem, which is a big problem for a City with 500+ persons.
- If meanwhile one of those Persons are deleted, it throws an EntityNotFoundException on the merge of the city, while it should just update the properties of the city and don't care about the persons.

Thanks for any and all help :)

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 12:40 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
What about making sure the city's person collection is not initialized? If the person collection is a proxy you shouldn't have the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 2:15 pm 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
Adrian Moos wrote:
What about making sure the city's person collection is not initialized? If the person collection is a proxy you shouldn't have the problem.


That's not possible, since it's been loading in a single query with "from City city left join fetch city.persons".

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 6:33 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
Quote:
don't care about the persons

Quote:
fetch city.persons


This looks like a contradiction: why fetch data you don't care about?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 7:58 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
When the user is editing a City, he's also shown a list of the persons in that city.
So the City select does a left join fetch to persons,
after which everything becomes detached,
the user is shown the city with its persons,
changes the city's properties (but can't change the persons list)
and finally the city is merged back into a persistent state.

_________________
http://www.ohloh.net/accounts/ge0ffrey


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