I have a Java EE 6 web application using container-managed transactions, and Context saving container via
@PersistenceContext private EntityManager em;
In the JPA layer, I have an inheritance strategy where MyExtendedClassA and MyEntendedClassB extend abstract MyClass .
I use stateless facade service classes to implement data access using the find , findAll , merge , persist , remove methods:
@Stateless public class MyExtendedClassAFacade { @PersistenceContext private EntityManager em; public void persist(MyExtendedClassA a) {
So far so good. Now I have to implement polymorphism regarding the behavior of extended classes. This behavior is to control some other objects in the database, so this requires a PersistenceContext (and therefore I need to use other stateless EJBs):
@Stateful public class MyBean { @EJB private MyClassFacade myClassFacade;
Is there any abstraction pattern that I can use for this purpose?
source share