• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate session caching problem

 
Lilian Fan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

This problem has disturbed me for almost a week. I cannot find any solution. I use hibernate add/modify/delete data in MySql. After adding data, I can see from MySql client that the entry is created to the table immediately. However, the newly created data will only be loaded by hibernate after some time (a minute for example).

In hibernate.cfg.xml, I set no cache provider by
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

For adding data
new Configuration().configure().buildSessionFactory();
Session s = PersistenceUtil.getSessionFactory().openSession();
Transaction tx = s.beginTransaction();
... //set attributes for office
s.save(office);
s.flush();
s.refresh(office);
s.clear();
tx.commit();
s.close();

For load data, we have:
SessionFactory sf = PersistenceUtil.getSessionFactory();
Session session = sf.openSession();
Query query = session.createQuery("from Office o where o.customer.customerId = ? order by officeId asc");
query.setInteger(0, customerId);
List list = (List) query.list();
session.close();

Is there anything missed? How can I load list of entries including the just updated ones immediately?

Please kindly help me out.. Thanks!

Regards,
Lilian
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35274
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lilian,
Welcome to JavaRanch!

We have a separate forum for Object Relational Tools like Hibernate. I'll move this for you.
 
Lilian Fan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

Thanks a lot~~
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do you have the
clear/flush/refresh
calls ? they are not required.

make sure you handle the Session/TX properly (try/catch/finally).

i don't see why your changes should appear onyl after a timeout if the TX is commited... can you turn on logging, and sql logging ? and see what you get there ?


pascal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic