-->
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: select after delete behavior unclear
PostPosted: Thu Aug 10, 2006 10:36 pm 
Newbie

Joined: Thu Aug 10, 2006 9:20 pm
Posts: 1
Hibernate version: 3.1.3

Code between sessionFactory.openSession() and session.close():
Session hsession = HibernateUtil.openSession();
hsession.flush();
hsession.clear();
HibernateUtil.getSessionFactory().evict(T.class);
t = hsession.createQuery("select t from T as t").list();
System.out.println("T: "+t.size());
Transaction tx = hsession.beginTransaction();
tx.commit();
t = hsession.createQuery("select t from T as t").list();
System.out.println("T: "+t.size());

Name and version of the database you are using:
MySQL 5

Here's the output:
19:19:20,149 INFO [STDOUT] T: 1
19:19:20,149 INFO [STDOUT] T: 0

So, what I'm trying to do is get a list of all rows of Table T. Another application is making changes to table T, and the behavior is not something I understand. When I add a row to table T, it shows up as expected. When I delete a row from Table T, it continued to show up despite everything I've tried to clear out the cache, until I eventually tried transactions. It seems that committing a transaction, even if it does no work, appears to tell Hibernate that it is free to go query the database instead of either cache for the data. I am mystified, and would really like an explanation or a better fix before my application becomes cluttered with dummy transactions.

Refresh and get do not seem well suited for updating collections, as I have to call get on each member and see if it returns NULL.

Is there a better way of forcing Hibernate to get fresh data from the database without this dummy transaction, and why is this dummy transaction solving my problem when flush, evict, and clear are not? Flush and clear should be redundant anyway, my implementation is guaranteeing a fresh openSession.

I also tried this as my query, but changing from Criteria was one of the things I tried to solve it before I got to transactions.

// t = hsession.createCriteria(T.class).list();


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.