-->
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: First Level Cache - does it need to be turned on?
PostPosted: Mon Mar 20, 2006 6:51 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
Hibernate version:3.1

Mapping documents:
<class name="com.trivin.bo.CodedValueType" mutable="false" table="CODED_VALUE_TYPE">
<id name="valueTypeID" column="TYPE_ID" type="integer">
</id>
<property name="code" column="CODE" length="30"/>
</class>



Code between sessionFactory.openSession() and session.close():
Session sess = super.getSession();
sess.createQuery("from CodedValueType").list();
sess.createQuery("from CodedValueType").list();



Full stack trace of any exception that occurs:

Name and version of the database you are using:
MSSql 2000


The generated SQL (show_sql=true):
Hibernate: select codedvalue0_.TYPE_ID as TYPE1_88_, codedvalue0_.CODE as CODE88_ from CODED_VALUE_TYPE codedvalue0_

Hibernate: select codedvalue0_.TYPE_ID as TYPE1_88_, codedvalue0_.CODE as CODE88_ from CODED_VALUE_TYPE codedvalue0_




Debug level Hibernate log excerpt:


The question is sort of 2 part.
1) Does hibernate not cache objects on read within a session?
2) Does the SQL output from Hibernate mean that it really went to the database and issued the SQL command?

If so, i'm trying to understand why the second call to get a list of simple objects resulted in another SQL command and access to the database.

If the sql trace doesn't indicate that it necessarily was issued, is there a way to tell whether subsequent calls to get a list of objects use the cache.


Top
 Profile  
 
 Post subject: Re: First Level Cache - does it need to be turned on?
PostPosted: Mon Mar 20, 2006 7:42 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
pgrillo wrote:

The question is sort of 2 part.
1) Does hibernate not cache objects on read within a session?

yes it does. But depending on your "lazy flag" initialization does it depend on whether the objects contain data or not. If Lazy is on and you are accessing a collection for the first time from loading the parent (ie parent.children) then you will be selecting again.

pgrillo wrote:

2) Does the SQL output from Hibernate mean that it really went to the database and issued the SQL command?

no. it actually did not issue the select command.

pgrillo wrote:

If the sql trace doesn't indicate that it necessarily was issued, is there a way to tell whether subsequent calls to get a list of objects use the cache.

The best way to convince yourself is to make sure to issue the first query, then stop your program in a debugger, and then update the database by changing a value in your table (make sure to commit), then continue with your debugger to the next query - if the query was actually issued it would contain the newly modified values...

You can setup hibernate to have different isolation levels, however; and you can ask hibernate to requery everytime too.

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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.