-->
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: how to refresh a set of objects efficiently - hints, tips?
PostPosted: Fri Sep 29, 2006 6:47 am 
Newbie

Joined: Mon Oct 10, 2005 6:10 am
Posts: 10
Hibernate version:
3.1
No 2nd-level cache, just session

Hello everybody,

is there an alternative way to refresh a huge set of object besides refreshing each object one by one, forcing quite a lot of SQL roundtrips or evicting all objects?

Here some pseudocode:

Alternative 1:
Drawback: lots of SQL-roundtrips
Code:
Transaction tx = session.beginTransaction()
List<MyClass> list = session.createQuery(...).list();
tx.commit();
for (MyClass item:list){
  session.refresh(item); --> forcing SQL roundtrip
}


Alternative 2:
Drawback: All evicted instances are stale
Code:
Transaction tx = session.beginTransaction();
List<MyClass> list = session.createQuery(...).list();
tx.commit();
for (MyClass item:list){
  session.evict(item); //item instance should not be used further, as it will be stale
}
list = session.createQuery(...).list();
//list contains now a brand new set of item instances with up to date data



Would-like-to-have-Alternative:
Code:
Transaction tx = session.beginTransaction();
List<MyClass> list = session.createQuery(...).list();
tx.commit();
list = session.createQuery(...).setRefreshPolicy(UPDATE).list();

with .setRefreshPolicy(UPDATE): if fetched object is already in session, then update this object else create a new instance

As far as I know, there is no way to refresh objects in this way. But maybe, someone might have an idea ...

Can objects (connected to a session) be marked in some way, that they get refreshed with some query containing up-to-date data?

Can some kind of intereceptor be installed somewhere to refresh stale objects with some query containing up-to-date date ?

Thanks in advance!


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.