users@glassfish.java.net

em.contains(entity) returns false, why?

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Wed, 4 Jul 2007 16:40:54 +0200

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(...) ?