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.  [ 3 posts ] 
Author Message
 Post subject: Strange behaviour on Session.evict when using query.iterate
PostPosted: Sun Jun 05, 2005 11:04 am 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
Need help with Hibernate? Read this first:
I was having problems to evict an instance from session, after double checking my classes equals and hashCode I started looking through
the tests that came on the distribution (Hibernate 3.0.5).
So, after looking through the tests of batch fetch I realized that my classes equals and hashCode were fine after being successful on evicting my classes from the session when I used query.list... but if I used query.iterate() and tried to evict the class immediatelly after running the iterator.next() the instance did not get evicted.
My question: is that the expected behaviour of the evict or not?

Sample code below:
Code:
//Problematic one, without Hibernate.initialize

      Session s = HibernateUtil.getSessionFactory().openSession();
      Transaction t = s.beginTransaction();
      
      String query = "from SomeClass";
      Iterator i = s.createQuery(query).iterate();
      obj1 = (SomeClass) i.next();
      
      if (s.contains(obj1)) {
         System.out.println("should contain");
      }
      s.evict(obj1);
      if (s.contains(obj1)) {
         System.out.println("should not contain");
      }
      else {
         System.out.println("ok, it wasn't anymore");         
      }
      t.commit();
      s.close();

Code:
//Fine, with Hibernate.initialize

      Session s = HibernateUtil.getSessionFactory().openSession();
      Transaction t = s.beginTransaction();
      
      String query = "from SomeClass";
      Iterator i = s.createQuery(query).iterate();
      obj1 = (SomeClass) i.next();
      
      if (s.contains(obj1)) {
         System.out.println("should contain");
      }
                Hibernate.initialize(obj1);
      s.evict(obj1);
      if (s.contains(obj1)) {
         System.out.println("should not contain");
      }
      else {
         System.out.println("ok, it wasn't anymore");         
      }
      t.commit();
      s.close();


---------------

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 11:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, its a little wrinkle that I need to fix at some stage.

Basically, the actual entity was evicted, but a *proxy* still points to the same session, which causes contains() to return true.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 05, 2005 11:25 am 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
I see, tks for the almost immediately reply.

_________________
Rafael Ribeiro


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.