3
votes

I'm having a strange situation where the injection of some Stateless EJBs into a Stateful prevents some lazy properties to be resolved by the Extended Persistence Context into a long running conversation in Seam 2.2.2

From what I've discovered, it seems that any find executed in a Persistence Context of a Stateless EJB injected into a Stateful one causes the clear() method to be called on the Extended Persistence context.

The methods are annotated with @TransactionAttribute(TransactionAttributeType.SUPPORTS)

Example:

@Stateful
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class BeanA {
        @PersistenceContext(type = PersistenceContextType.EXTENDED) EntityManager em;
        @EJB BeanB beanB;

        public MyClassA find(Long id) {
            return em.find(MyClassA.class, id);
        }

        public void method() {
             MyClassA a = find(2);
             em.contains(a); // true
             beanB.find("myId");  // Now every object returned from A's EM are detached.
             em.contains(a); // false
        }
}

@Stateless
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class BeanB {
        @PersistenceContext EntityManager em;

        public MyClassB find(String id) {
             return em.find(MyClassB.class, id);
        }
}

Can anyone confirm me this?

2

2 Answers

-1
votes

Not sure about what causes the clear() behaviour. However, while you can use EJB3 injection with @EJB and @PersistenceContext in your EJB components, you should use @In to inject both BeanB and the entity manager in order to have the conversation scoped seam managed entity manager propagated across your components.