users@glassfish.java.net

Re: em.contains(entity) returns false, why?

From: Sahoo <Sahoo_at_Sun.COM>
Date: Wed, 04 Jul 2007 23:59:00 +0530

How are you obtaining the em? Are you using the same persistence-unit in
both the EJBs or not? Does this article [1] help you in resolving the issue?

Thanks,
Sahoo

[1]
http://weblogs.java.net/blog/ss141213/archive/2006/10/persistence_con.html

Witold Szczerba wrote:
> Hi there,
> I have a situation, I do not know why, entity manager returns false in
> the following case:
>
> there are two stateless session beans:
>
> @Stateless
> public class LoanCacheServiceBean implements
> LoanCacheServiceLocal, LoanCacheServiceRemote {
> .........
> public LoanCache getCache(Long loanId, Date date) {
> .......
> return loanCache; //<-- em.contains(loanCache) returns TRUE here
> }
> }
>
> @Stateless
> public class TransactionServiceBean implements
> TransactiondServiceLocal {
>
> @EJB
> private LoanCacheServiceLocal loanCacheServiceBean;
>
> ..................
> public void someMethod() {
> LoanCache loanCache = loanCacheServiceBean.getCache(.....)
> em.contains(loanCache); //NOW, loanCache IS FALSE, why?
> }
> }
>
>
> As you can see, before getCache(...) returns, loanCache is managed by
> entity manager, but inside someMethod() from another session bean,
> that entity is not managed anymore. All is happening within same
> transaction scope.
>
> When two entity managers are participating in the same transaction,
> shouldn't they return the same result of em.contains(...) ?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>