-->
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: Issues with re-attaching read-only/detached objects
PostPosted: Fri Oct 03, 2014 5:29 pm 
Newbie

Joined: Thu Aug 14, 2014 5:13 pm
Posts: 3
So I'm working in Jboss EAP1, so the version of hibernate may be a little old. If this has been fixed subsequently, just let me know. I'm dealing with EJB3.1 mostly, but have slipped into hibernate specifics where necessary to get the extra performance necessary to get work done.

I'm working on a very large enterprise software which uses very very nested behaviour logic inside EJB's which run for several seconds. During this time, arbitrary sets of entites are fetched into the code from the DB. Over several permutations of performance work, I've attempted detaching, selective flushing with commit mode, etc.. to improve hibernate performance. For the most part, its been successful, but to avoid exceedingly long flush operations, I've recently defaulted basically all DB fetches as read-only.

Code:
/* In TX, read-only by default */
someMethod() {
   myEntity = entityManager.createQuery(.....).getSingleResult(); /* Just for simplicity */
   
   entityManager.detach(myEntity);

   /* Here the entity is out of the live entity pool, but still resident in hibernate as a 'detached entity'.  Oddly, it is still marked as read-only in its EntityEntry even though its already been detached from the live pool. */
   myEntity.setSomeValue("DIFFERENT VALUE");

   entityManager.merge(myEntity);

   entityManager.flush();
}


Inside the flush code, it finds a EntityEntry for myEntry (since its detached but styill resident) but since it was flagged as read-only before being detached, the entity's change doesn't get persisted back to the DB because the flush listener doesn't think anything's changed (because it was flagged as read-only prior).


Top
 Profile  
 
 Post subject: Re: Issues with re-attaching read-only/detached objects
PostPosted: Fri Oct 03, 2014 6:51 pm 
Newbie

Joined: Thu Aug 14, 2014 5:13 pm
Posts: 3
Note, my 'solution' to the problem was to purge the entity's key EntryEntry from the persistence context immediately before adding it back in, which makes everything work, though a little more klunky than it should've been. I wish I know why this behaviour was occuring. Ideally when an entity is detached, it should be setting the entry writable again, or at least ignoring the status when detecting that the entity is detached?


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.