-->
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.  [ 8 posts ] 
Author Message
 Post subject: refresh not working from RC to GA
PostPosted: Wed Oct 25, 2006 8:41 pm 
Newbie

Joined: Mon Jul 03, 2006 4:28 pm
Posts: 15
Hi Guys,

with hibernate 3.2 RC I used to use detached entities and send them back and forth across the boundary between my ejb layer to my web layer (from session bean to jsf managed bean) like value objects. It worked really well, and I just did an entityManager.refresh(myEntity) before working with it to reattach it.

Now, when I do an entityManager.refresh(myObject) on an object that has previously been persisted by hibernate, but detached to the web layer and sent back to be reattached...it throws the following exception

Caused by: java.lang.IllegalArgumentException: Entity not managed
at org.hibernate.ejb.AbstractEntityManagerImpl.refresh(AbstractEntityManagerImpl.java:260)
at com.sun.enterprise.util.EntityManagerWrapper.refresh(EntityManagerWrapper.java:783)


Which I discovered is related to jira ticket #EJB-205 (http://opensource.atlassian.com/project ... se/EJB-205)

So, my question is...now that you can't use refresh to reattach a detached object, what is the correct way to do it?

Cheers
Adam


Top
 Profile  
 
 Post subject: oh, by 'now'.....
PostPosted: Wed Oct 25, 2006 8:43 pm 
Newbie

Joined: Mon Jul 03, 2006 4:28 pm
Posts: 15
....by 'now' I mean 3.2GA

I've just upgraded from 3.2RC2 to 3.2GA


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 8:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
session.lock(, LockMode.NONE) and then em.refresh() will do what you want.
But I don't recommend it for data integrity (neither the way you did it previously).

_________________
Emmanuel


Top
 Profile  
 
 Post subject: what would you recommend
PostPosted: Wed Oct 25, 2006 9:03 pm 
Newbie

Joined: Mon Jul 03, 2006 4:28 pm
Posts: 15
is there any best practice for detaching entities that you know of anywhere?


Top
 Profile  
 
 Post subject: oh...and...
PostPosted: Wed Oct 25, 2006 9:05 pm 
Newbie

Joined: Mon Jul 03, 2006 4:28 pm
Posts: 15
...I don't have access to the session...I'm using stock standard ejb3

so

@PersistenceContext
private EntityManager em;

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int getFriendCount(UserAccount acct){
em.refresh(acct);
return acct.getFriends().size();
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i don't think "stock standard ejb3" supports reattachment.

you would need to use .merg() first...but not sure that gives the behavior you want.

Is that correct Emmanuel?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 1:55 pm 
Newbie

Joined: Mon Jul 03, 2006 4:28 pm
Posts: 15
yeah, you're right about reattachement. I read a couple of articles and the all say you have to do another find (or, as you say, a merge).

So (from what I can gather) my method really should have been:

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int getFriendCount(int userAccountId){
UserAccount acct = em.find(UserAccount.class, userAccountId);
return acct.getFriends().size();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
find() is lighter than merge() for what you want to do.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.