I need to rollback in EJB 3 Stateless SessionBean (CMT, JBoss version 5), for which I am using
sessionContext.setRollbackOnly();
This sessionContext is injected using @Resource annotation. My questions: 1) Is it preferred way to rollback in EJB3?
2) Why Jboss complains on deployment if I use public setter injectio开发者_如何学JAVAn
// throws exception on deployment.
private SessionContext sessionContext;
@Resource
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
but following works fine:
@Resource
private SessionContext sessionContext;
Here is the exception in first case:
javax.ejb.SessionContext is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at javax.ejb.SessionContext
at public javax.ejb.SessionContext invoice.sap.service.jaxws.SetSctx.arg0
at invoice.sap.service.jaxws.SetSctx
javax.ejb.SessionContext does not have a no-arg default constructor.
this problem is related to the following location:
at javax.ejb.SessionContext
I assume the EJB is an @WebService, which is why you're getting JAXB errors. Try:
@Resource
@WebMethod(exclude=true)
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
Alternatively, change the method visibility or add the final modifier (only public non-final non-static methods are webservices methods).
1) yes
2) Dunno, perhaps a bug, perhaps deprecated. I've glanced through the EJB 3.1 spec and there I only saw the @Resource SessionContext sessionContext
form, while the EJB 3.0 spec also showed the setter injection.
精彩评论