-->
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: query cache and insert="false" update="false
PostPosted: Thu Mar 09, 2006 10:11 am 
Newbie

Joined: Thu Mar 09, 2006 9:58 am
Posts: 3
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)??


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.