Forcing object reload

Is there any way to force the persistent manager to re-load objects. This is the problem I am having:
1- I load an array of objects A from the DB
2- I modify one of the object and save() and commit() to the DB
3- When I look at the DB, the object is updated but when I read the initial list (from step 1) the object is not modified. If I try reloading (using the Factory class) it seems to be reloading from cache rather then the DB. Any way to prevent this?
Martha Greg

Dear Martha,

Thank you for your message. In order to reduce the number of database access and for fast loading, the persistable objects will be cached in the session. You can remove the cache by using this

PersistentManager.instance().getSession().evict(object);

where the object is the persistable object that you want to remove from cache. If you have any further questions, please feel free to contact us again.

Best regards,
Rain

Hi Rain,

I ran into this to, and was happy to find this entry in the Forum. When I search on “evict” in the user guide - no luck. I’d like to see the default eviction cycle and other documentation related to this kind of issue, and maybe some best practices in the guide for when to manually evict, and when to aviod it.

Brien

Hi Brien,

I will let our documentation team know about your need. Meanwhile, if you have any questions about the use of evict, please feel free to post here.

Best regards,
Jick

Hi support, hi all,

as the freshness of objects is critical to my application the issue of evicting/refreshing objects has been keeping me busy for a while.

As my impression is, closing and re-opening a session is much more efficient or just even effective, than evicting a single object from the cache.

More detailed: When I evict a single object from the cache my impression is that the object does not or not instantly get removed from and reloaded into the cache, when needed. This is inacceptable, as I do want any actions to take effect immediately, and not by chance or after a while.

When I close and re-open my session, the effect (or the change in the object) is instantly reflected.

Now I’m wondering if it has any negative side-effects, closing and re-opening a session!? Like using resources, because all objects have to be reloaded!?

I’d be grateful if you could offer some more detailed insight into this topic. Or are you the wrong address, because those are Hibernate issues!?

Thanks + regards

Hi christine,

A session contains a cache of objects. With evict, object will be removed from the cache, so the next query will load again from the database. Refersh will reload the object from the database again.

About re-opening of session, the session with all its cache will be removed, and the new session will work like as if the application is restarted. There won’t have any negative effect, except that the cache will be removed.

Best regards,
Jick

Hi Jick,

thanks for your reply!

Yet I’m sorry to say that it doesn’t help me or tell me anything new. What you’re describing is what’s already in the documentation, what I have already written in my posting and how it’s supposed to be.

But I guess this is simply the wrong place to ask detailed Hibernate questions…

What I experience is that objects do not get removed immediately, when using evict. It would be interesting to get to know why, or what I might be doing wrong. I already turned off browser caching and all that.

Secondly, the application does not behave as if it were restarting. When the application starts, my debug log gets crowded with Hibernate object loading, configuration and all that. The debug log is quite quiet when doing a session close and a new getSession.

So it seems as if the Hibernate session does not get closed completely, or the cache does not get reloaded completely.

Anyways, never mind. I’m glad to be able to use the tool, which is very helpful. And to get expert advice I’ll ask experts :wink: (and not VP first level forum support, resp. VP documentation) or do research on my own.

Stating the obvious is never helpful, neither in product documentation nor in a support situation.

Like I said, thanks anyways and never mind. I’m not trying to “unmake” your day. The product is fine. And sometimes this support forum does help. :wink:

Best regards.

Hi christine,

Sorry if my response was not good enough to address your query.

Secondly, the application does not behave as if it were restarting. When the application starts, my debug log gets crowded with Hibernate object loading, configuration and all that. The debug log is quite quiet when doing a session close and a new getSession.

You are right. Renewing of session is quiet, it does not require reloading the configuration. Turning on show_sql in configuration can help checking whether Hibernate has really retrieved data from the database.

Best regards,
Jick

Thanks for the additional information.

You are welcome. Have a nice weekend! :smiley:

FYI:
I ran into a similar problem noticing that my classes were indicating different results than what was in my database after updates, and rather than using the Evict approach I’m exploring another solution path.

Details on separate thread:
http://forums.visual-paradigm.com/posts/list/0/2651.html#20158

Hi LW,

Let’s continue at:
http://forums.visual-paradigm.com/posts/list/0/2651.html#20158

Best regards,
Jick