users@glassfish.java.net

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

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 05 Jul 2007 01:27:46 +0530

Can you check if you have actually annotated LoanCacheServiceLocal as
@Local or not?

I tried using a simple test case, but could not reproduce the behavior
you are reporting. I am using GlassFish V2 b52, but I don't think that
matters. You have to supply a simple test case that demonstrates the
problem.

Thanks,
Sahoo

Witold Szczerba wrote:
> Well, both session beans use injection to obtain entity manager:
>
> @PersistenceContext
> private EntityManager em;
>
> Both session beans belong to the same EJB module which uses JTA. Looks
> like I should not have
> em.contains(entity) == false in TransactionServiceBean, but that is
> what happens :/
>
>
> 2007/7/4, Sahoo <Sahoo_at_sun.com>:
>> 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
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>