-->
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.  [ 2 posts ] 
Author Message
 Post subject: Does Hibernate cache based on objects (results) or queries?
PostPosted: Mon Jun 07, 2004 2:50 pm 
Newbie

Joined: Wed Apr 21, 2004 12:45 am
Posts: 11
To clear up what I'm asking... I have an object User that has a one-to-one relationship with another object UserType. I have a getter on the User that retrieves an instances of UserType.

I have another method that is used that returns an entire list of all the UserTypes defined in the system. I'm wondering if Hibernate can notice that the results its getting from my User.getUserType method and UserTypeDAO.getAllUserTypes methods are the same object in some cases, and will use an object that it already has cached, or if it is hitting the database every single time.

To give a better example, lets say I define one user type in my system called "Administrator", and I have 20 users that are all assigned that type.

Now lets say I have a JSP page that displays a list of my users and their types using the method call: user.getUserType().getName();

I'm expecting that the first call to that method will hit the DB and load the user Type, and the 19 other method calls to the DB will actually user the cached value, is this correct?

Now I'm also wondering if say someone clicks on "View All User Types" and sees a list with 1 user type in it of "Administrator" that I got via the call UserTypeDAO.getAllUserTypes(), if that object being displayed with "userType.getName()" was loaded from the Hibernate cache, or if that method call hit the database separately, even though me viewing the users on the previous page already loaded the object I needed.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you are inside the session scope, one object will always be loaded once from the database. If you need this over session scope, look at the various second-level caching options.


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