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.
|