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!