-->
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.  [ 4 posts ] 
Author Message
 Post subject: N+1 queries being fired when a detached object is merged
PostPosted: Tue May 14, 2013 11:39 pm 
Newbie

Joined: Thu Jun 12, 2008 9:52 pm
Posts: 11
Hi,

I have an application in which I am using JPA over Hibernate. I have a class named Employee and an associated collection of List<Address> addresses(I have specified this as LAZY). When the Employee page is taken to be edited through UI, I put Employee object in HttpSession. When the user makes changes on UI and submits, I get these changes made reflected on the Employee object in HttpSession(I am using Spring MVC for this). Now, when I try to update the Employee object using EntityManager.merge(), its firing n+1 queries to first fetch the list of addresses and then it does the update. I want to avoid these n+1 queries for they are affecting the performance of the application. I feel when I retrieve the Employee from HttpSession, it will be detached.

I do not want to use an OpenSessionInViewFilter for I do not want lengthy Hibernate sessions. Can anyone suggest a solution for this?


Top
 Profile  
 
 Post subject: Re: N+1 queries being fired when a detached object is merged
PostPosted: Thu May 16, 2013 8:09 am 
Newbie

Joined: Sun Oct 02, 2005 12:49 am
Posts: 15
Please post the mapping. Not worked with JPA as such or detached objects. We typcially use DTOs. Anyways, have you specified cascade? My guess is that you have. Also you may want to checkout the dynamicUpdate attribute of the mapping file. You may want to set it to true.


Top
 Profile  
 
 Post subject: Re: N+1 queries being fired when a detached object is merged
PostPosted: Thu Jun 20, 2013 10:34 pm 
Newbie

Joined: Thu Jun 12, 2008 9:52 pm
Posts: 11
Thanks, ranjan. But, will cascade cause n+1 to be fired?


Top
 Profile  
 
 Post subject: Re: N+1 queries being fired when a detached object is merged
PostPosted: Fri Jun 21, 2013 9:57 am 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
Whay you don't want to use OpenSessionInFiewFilter. I don't think it keeps the hibernate session open for too long.


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