Hi
I found a problem with query cache and
insert="false" update="false" atributes.
When object is retreived from cache, some properties are null, but when object is loaded directly from db everything is ok.
Hibernate version:
Hibernate 3.1.2
Mapping documents:
<?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>
<class name="test.User" table="users">
<cache usage="read-write"/>
<id name="id">
<generator class="uuid.hex"> </generator>
</id>
<property name="name"/>
<property name="password"/>
<property name="testId" column="TEST"/>
<property name="testId2" insert="false" update="false" column="TEST"
/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session s = HibernateUtil.currentSession();
Transaction t = s.beginTransaction();
User u = new User();
u.setName("name");
u.setPassword("password");
u.setTestId("id4");
s.saveOrUpdate(u);
User u1 = (User) ((s.createQuery("select user from User as user where user.name=?").setString(0,"name").setCacheable(true).setCacheRegion("userRegion").list()).get(0));
System.out.println("u1="+u1.getTestId()+","+u1.getTestId2());
t.commit();
HibernateUtil.closeSession();
s = openSession();
t = s.beginTransaction();
User u2 = (User) ((s.createQuery("select user from User as user where user.name=?").setString(0,"name").setCacheable(true).setCacheRegion("userRegion").list()).get(0));
System.out.println("u2="+u2.getTestId()+","+u2.getTestId2());
t.commit();
HibernateUtil.closeSession();
s = openSession();
t = s.beginTransaction();
User u4 = (User) ((s.createQuery("select user from User as user where user.name=?").setString(0,"name").setCacheable(true).setCacheRegion("userRegion").list()).get(0));
System.out.println("u4="+u4.getTestId()+","+u4.getTestId2());
t.commit();
HibernateUtil.closeSession();
Result:
15:01:35,756 INFO [StandardQueryCache] starting query cache at region: org.hibernate.cache.StandardQueryCache
Hibernate: insert into users (name, password, TEST, id) values (?, ?, ?, ?)
15:01:36,077 INFO [StandardQueryCache] starting query cache at region: userRegion
Hibernate: select user0_.id as id1_, user0_.name as name1_, user0_.password as password1_, user0_.TEST as TEST1_ from users user0_ where user0_.name=?
u1=id4,null
Hibernate: select user0_.id as id1_, user0_.name as name1_, user0_.password as password1_, user0_.TEST as TEST1_ from users user0_ where user0_.name=?
u2=id4,id4
u4=id4,null
Expected Result:
(...)
u2=id4,id4
u4=id4,id4
Name and version of the database you are using:
HSQLDB 1.8.0, Oracle 9.2
Why in object loaded from cache testId2 is null??
When I comment out
<cache usage="read-write"/>
I got expected result (id4)??
|