-->
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: How to avoid unnecessary DB hits i for below scenario
PostPosted: Tue Jan 07, 2014 11:52 pm 
Newbie

Joined: Sun Aug 04, 2013 8:16 am
Posts: 1
Hi All,

In my application I have loaded the user information and stored in Http session object.
In one scenario I want to save record in address table which has userid as foreign key.
Here when I try to save address Object which has a User object by using below code:
Address address=new Address();
User user=new User()
user.setUserId(1);//Id will be retrieved from Http session object.
address.setUser(user);
session.save(address);
//The above lines of code throws exception.

but when I use below lines of code it works perfectly but hits the DB to fetch user object.
Address address=new Address();
User user=(User)session.get(User.class,1);//one hit for fetching user and same for session.load() also
address.setUser(user);
session.save(address);//one hit to save address

How to avoid the hit to fetch user as I have userid already with me.


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.