Hello,
I have a somewhat unique application of Hibernate. I have a server-side code that is accessed by a telnet client. Every time a screen is displayed to the user, it blocks the execution thread (Imagine a UI application with long series of modal dialog boxes...)
Without going into much detail, I'll say that the code:
1. Keeps Session open for extended period of time
2. Keeps Session open over multiple interactions with the user.
Sooner or later the data held my the objects becomes stale. Ideally, I would like to keep the code as simple and as readable as possible (so avoid evicting objects from cache, clearing cache, closing sessions, etc),but every time application returns from UI interaction, I would like Hibernate to 'forget' any data it had in the session cache.
For example, here's basic flow I'd like
1. SKU sku=session.load(SKU.class,...); // obtain SKU object somehow.
2. String dummy=sku.getDescription(); //Hits DB
3. String dummy=sku.getDescription(); //Does NOT DB
4. Display screen to user.
5. String dummy=sku.getDescription(); //Hits DB !!!! - VERY IMPORTANT
6. String dummy=sku.getDescription(); //Does NOT DB
7. Display screen to user.
8 ...
Clearing session cache (session.clear() ) is not a solution because the code may still have handles on uninitialized proxies and collections. Ideally, I would like to do the following:
1. Force Session to ALWAYS give me proxies instead of real objects for any results. So wether I do
SKU sku = (SKU)session.load(SKU.class,new Long(1));
or
SKU sku= (SKU)session.createQuery(" from " + SKU.class.getName() +" where id=1").list.get(0);
or any other combination of code, i want to get back a proxy.
This sounds counter-intuitive, and counter-performant, but, what I want to do, then is:
2. Have some Session-wide action to 'reset' any proxies back to unloaded state whenever the user screen is closed (i.e. modal dialog finishes), so that next time it is accessed, it hits DB.
Sorry for the long-winded explanation.
Is there anything in Hibernate Session object that will let me do step 1 (i.e. force proxies every time) ? Probably if I solve that issue, I can figure out how to reset them back to uninitialized form.
Thanks in advance,
Alex
|