-->
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: Session.evict vs Session.clear best practice
PostPosted: Sat Jun 19, 2010 7:57 am 
Newbie

Joined: Sat Aug 09, 2008 11:24 am
Posts: 5
Hi,

I have an application with a fairly complex domain model. For the most part, persistence is straightforward but I have come across a few cases where I need to evict objects from the Persistence Context. An example of this might be where a client app is supplying a remove request to a business service:

Code:
@Transactional
public void removeFoo (final Integer fooId) {

// We need to know what the "x" property of the object is before we delete it
// This will have brought a whole load of associated objects into the Persistence Context with it
Foo fooToRemove = this.fooPersistenceService.get (fooId);

// Now take some action based on the property
if (fooToRemove.getX() == 42) {
// Do Something
}

// Need to get rid of Foo to make sure it doesn't get "re-saved by cascade"
this.fooPersistenceService.evict(fooToRemove);

// Now we can remove the object
this.fooPersistenceService.remove(fooId);

}



This is usually not a problem. However, I have noticed that as the domain relationships become more complex and there are more bi-directional relationships, evicting an object completely becomes more and more difficult as I have to ensure that the evict is cascaded properly. I understand that this is for good reason.

It would be far simpler for me to use Session.clear(). There are a handful of wierd corner cases in the app where this would make life a lot easier.

My apologies for not providing actual code but, unfortunately, this is not possible. However, this is more of a design question so hopefully the lack of real code is not a problem.

So, my questions are:

1) Is there any overhead associated with calling clear() instead of evict()?
2) Would the experts consider me replacing evict() with clear() to be a monumental hack?

Thanks in advance,

Si


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.