A question about entity manager in stateless session bean.

JSR 220 ejbcore, page 47 : stateless session bean: All business object references of the same interface type for the same stateless session bean have the "same object identity", which is assigned by the container.

So, if we have two session beans in client code...

@EJB Cart cart1;

@EJB Cart cart2;

then cart1.equals(cart2)==true

If we declare entity manager in stateless session bean:

@PersistenceContext( unitName="ds" ,type=PersistenceContextType.TRANSACTION)

private EntityManager em;

If cart1 and cart2 are the same reference, do we have any problem when using the same reference(maybe the same em? ) to get data from db?

[739 byte] By [ncu_askaa] at [2007-11-27 10:54:23]
# 1

As long as you manage your EM's in way that is thread safe manner, I think there shouldn't be an issue.

Are you performing the different actions with Cart1 and Cart2?

-K

cadence2.0a at 2007-7-29 11:49:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

> If cart1 and cart2 are the same reference, do we have

> any problem when using the same reference(maybe the

> same em? ) to get data from db?

No. In EJB, there is a distinction between the EJB reference and the bean instance.

Each time you make an invocation on an EJB reference for a stateless session bean,

the container can choose *any* instance of that bean's bean class to process the

invocation.That's true whether you invoke the same reference multiple times or

two difference references to the same bean.

Each bean instance is guaranteed to be single-threaded.

ksaksa at 2007-7-29 11:49:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...