my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0: EntityManager Injection in SLSB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0: EntityManager Injection in SLSB" Watch "EJB 3.0: EntityManager Injection in SLSB" New topic

EJB 3.0: EntityManager Injection in SLSB

Morten Franorge
Ranch Hand

Joined: Jul 29, 2005
Posts: 137
Is it safe to inject an EntiyManager in a SLSB? I mean, the EM isn't thread safe?

SCJP 1.4, SCBCD 1.3, SCBCD 5.0, SCEA J2EE, SCEA 5.0
Merrick Schincariol

Joined: Aug 15, 2006
Posts: 17
Good question. The intention of the spec at least (reading between the lines in section 5.6), is that the entity manager is safe to use when injected into a stateless session bean. This is because there is no persistence context associated with a transaction-scoped entity manager. Instead, the persistence context is acquired dynamically, either from the transaction or created temporarily when required outside of a transaction.

In OC4J, the entity manager you inject is really a lightweight and thread-safe proxy that does the right thing when a method on the entity manager is invoked.

The relationship between persistence units, persistence contexts and the things that actually get injected into your application can be complex. We devoted an entire chapter in our book on this topic for just this reason.


subject: EJB 3.0: EntityManager Injection in SLSB
Similar Threads
Who didn't use SLSB for DAO?
Is it necessary to use statless sessiob bean as proxy to web service?
stateless Session Bean Thread safety issue
concurrent access?
How does an EJB treat multiple requests when compared to a Servlet?