EJB 3.1 Transaction, EntityManager

I have an application that processes IQ stanzas through smack (an event-based java library). Now we are switching from Vanilla Tomcat to glassfish 3.1, and I would like to switch to ejb 3.1.

@Stateless
public class DispatchIQService {
    private static Logger log = Logger.getLogger(DispatchIQService.class);

    @PersistenceContext(unitName="hq")
    private EntityManager em;

    ....

    public void process(XMPPConnection connection, IQ rawRequest) {
    log.debug("Raw Provider IQ: " + rawRequest.toXML());

    RawResponse answer = null;

    try{
        StateWrapper state = new StateWrapper(em, connection, rawRequest);

        // parsing raw xml from request
        rawRequest.parse();
        // processing action
        answer = rawRequest.dispatchAction(state);

Due to the event-based library, I get the correct object for each request. StateWrapper is an old construction for sending em, request and connection via message processing. I want to remove this as soon as possible using ejbs and dependency injection.

With rawRequest.dispatchAction (state), I pass the control to the request object to search for the facade service and start with business logic.

@Override
public RawResponse dispatchAction(StateWrapper state) {
    ModelFacade modelFacade = Core.lookup(ModelFacade.class);
    return modelFacade.listModels(state, childElement.getIds());
}

Core.lookup is just looking for jndi to get the necessary Bean. In this bean I can enter em.

@Stateless
public class ModelFacade {

    @PersistenceContext(unitName="hq")
    private EntityManager em;

    ... 
public RsModelListIQ listModels(StateWrapper state, List<Long> list) { ...

: emter , em DispatchIQService? ? em?

0
1

, EntityManager " JPA". - EntityManager, , , EntityManager . , DispatchIQService, ModelFacade, , .

+1

All Articles