-->
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: Evict from the Session and the role of Second-Level cache
PostPosted: Wed Feb 23, 2005 1:53 pm 
Newbie

Joined: Tue Feb 22, 2005 11:53 am
Posts: 1
Hello,

I'm using Hibernate 2.1.7 with OSCache as Second-Level cache.
In the hibernate.properties I setup hibernate.show_sql true.

I'm trying to simulate simple scenario where the object first of all gets loaded into JVM then it gets evicted from the session cache and then loaded once again. So in terms of JAVA it looks like:

bsh % net.sf.hibernate.Session s = HibernateUtil.getSession();
bsh % // lets load the object first time
bsh % HibernateUtil.beginTransaction();
bsh % offer = s.load(Offer.class,new Long(1));
<af.cache.model.Offer@a974c7[
name=Test MoS Catalog Offer
id=1
version=0
created=2005-02-23 12:13:37.0
]>
bsh % HibernateUtil.commitTransaction();
bsh % // the object gets evicted from the session cache
bsh % HibernateUtil.beginTransaction();
bsh % s.evict(offer);
bsh % HibernateUtil.commitTransaction();
bsh % // lets load the object second time
bsh % HibernateUtil.beginTransaction();
bsh % offer = s.load(Offer.class,new Long(1));
<af.cache.model.Offer@a974c7[
name=Test MoS Catalog Offer
id=1
version=0
created=2005-02-23 12:13:37.0
]>
bsh % HibernateUtil.commitTransaction();

At the moment when I'm trying to load the object second time I see that:
1. LOCK/GET/UNLOCK are being called on the second-level cache by Hibernate and the object is found in the cache
2. Hibernate generates the query:
Hibernate: select offer0_.id as id0_, offer0_.version as version0_, offer0_.NAME as NAME0_, offer0_.created as created0_ from OFFER offer0_ where offer0_.id=?
3. LOCK/GET/UNLOCK are being called AGAIN on the Second-level cache by Hibernate

So I'm wondering:
1. Does the fact that Hibernate generates the query mean there is effective hit to DB?
2. If "YES", what is the reason behind that?
2. Why there is second call of LOCK/GET/UNLOCK?

That's my mapping file:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="af.cache.model.Offer"
table="OFFER"
polymorphism="explicit"
dynamic-update="false"
dynamic-insert="false">

<cache usage="read-write" />

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null">

<generator class="sequence">
<param name="table">HIVAL</param>
<param name="column">NEXT</param>
</generator>
</id>

<version
name="version"
type="int"
column="version"
access="property"
unsaved-value="undefined"/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="NAME"/>

<property
name="created"
type="timestamp"
update="false"
insert="true"
access="property"
column="created"/>

</class>
</hibernate-mapping>

Hope, I was clear!


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.