Hi guys,
I'm new to Hibernate and I'm having a problem with second-level caching in read-write mode.
I have searched the internet and the forum, I fould a similar problem (
http://forum.hibernate.org/viewtopic.ph ... 0c2e1cd6b7). However, my problem is a bit different.
The problem is: my code is only a simple piece like this:
Code:
//Open session & Start transaction
TestObj o1 = (TestObj)hibernateSession.get(TestObj.class, 1);
TestObj o2 = (TestObj)hibernateSession.get(TestObj.class, 2);
TestObj o3 = (TestObj)hibernateSession.get(TestObj.class, 3);
//Comit transaction & close transaction
//a few moment latter (still the same SessionFactory)
//Open session & Start transaction
TestObj to1 = (TestObj)hibernateSession.get(TestObj.class, 1);
TestObj to2 = (TestObj)hibernateSession.get(TestObj.class, 2);
TestObj to3 = (TestObj)hibernateSession.get(TestObj.class, 3);
//Comit transaction & close transaction
When to1, to2 and to3 are loaded, there are excatly 3 SELECT queries in postgresql's log like this:
Code:
LOG: duration: 0.023 ms statement: EXECUTE <unnamed> [PREPARE: select testobj0_.id as id19_0_, testobj0_.v as v19_0_ from
tblTest testobj0_ where testobj0_.id=$1]
When I switch from <cache usage="read-write" />
to <cache usage="nonstrict-read-write" />
this does not happen anymore.
I don't really know what's wrong with my read-write caching setting :-(
Any help is appreciated :-)
Regards,
Tom
My hibernate configurations are as the following:
Hibernate version: 3.2.1-GA 2nd-level Cache: EhCache 1.2.4RC
Mapping documents:The database table:Code:
CREATE TABLE tbltest (
id serial,
v integer NOT NULL,
primary key (id)
)
Mapping file:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="test">
<class name="TestObj" table="tblTest">
<cache usage="read-write" />
<id name="id" column="id" type="integer">
<generator class="identity" />
</id>
<property name="value" column="v" type="integer"
not-null="true" />
</class>
</hibernate-mapping>
Name and version of the database you are using: Postgresql 8.1 on Fedora Core 5 box