learn java
The moose likes Object Relational Mapping and the fly likes evict() method doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "evict() method doubt" Watch "evict() method doubt" New topic

evict() method doubt

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9763


Why would I need this method? Why would I clear off the cache using this method, in the following scenario that I got from the Hibernate Quickly book,

Event one = (Event) session.load (Event.class, eventId);
one.setName ("Culturals");

if (session.contains(one)) {
session.evict ();

Event two = new Event ();
two.setId (eventId);
two.saveOrUpdate ();

Is it for the reason that I simply want to associate the id with another instance, I use the evict () method?

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17260

Yes, lots of reasons to use evict. If you load too many objects into the Session you can run out of memory. So if you end up doing any long running sessions, you might want to evict out objects to save memory. It is a method that allows you full control over the cache's. There is also an evict() method in the Factory class to remove objects from the second level cache, if you are using second level cache.

Hope that helps clarify things for you.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9763

Thanks Mark. Totally understood!
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: evict() method doubt