-->
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.  [ 2 posts ] 
Author Message
 Post subject: Can I remove em.clear() calls from my code safely?
PostPosted: Fri Nov 25, 2011 3:04 pm 
Beginner
Beginner

Joined: Wed Sep 06, 2006 12:08 pm
Posts: 48
Location: Warsaw - Poland - Europe - Milky Way
Hi

I've got an app where I have several places with the following code:

Code:
em.fush();
em.clear();
// ...


Are the cases where removing em.clear() calls from the code can change my app behaviour / logic?
I know that em.clear() is freeing memory but this is not the issue in my case (in my app) so forget about freeing memory in this thread.

Take care,
Adam

PS.
Sometimes I must use em.flush() (here: flush not clear) because I need to call some Oracle PL/SQL database procedures.


Top
 Profile  
 
 Post subject: Re: Can I remove em.clear() calls from my code safely?
PostPosted: Sun Nov 27, 2011 6:01 pm 
Newbie

Joined: Wed Jun 01, 2011 1:16 am
Posts: 4
em.find() will now return the same entity instead of a copy. If your app relies on "==", then that's one way it could be different. Another way is if you make any changes to the entity after the flush(); before such changes would be lost; now they'll be flushed on commit() (if your flush mode is so configured). Also, operations like merge(), delete(), refresh() will obviously behave differently on attached vs. detached entities.

I'd recommend spending whatever time it takes to understand why your app used clear() in the first place and get rid of it. It reeks of "voodoo programming". My reason is that clear() breaks the normal session lifecycle. Just like you should prefer declarative @Transactional management, you should declaratively manage your session's lifecycle and flush mode. Bugs due to incorrect or misunderstood use of clear() and flush() are some of the hardest to debug and fix in my experience.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.