我有一个jax-ws服务,但当我在其中运行hibernate事务时,我会得到以下异常:
Caused by: java.sql.SQLException: DSRA9350E: Operation Connection.commit is not allowed during a global transaction.
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.commit(WSJdbcConnection.java:1104)
at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:170)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:146)
... 47 more
我没有使用XA数据源,客户端是一个未连接到任何数据库的junit。据我所知,我没有对这个web服务做任何事情,让它认为我想要一个全球交易。我没有在websphere中设置任何策略集,事实上,当我查看管理控制台时,我没有看到任何策略集。
我的hibernate事务使用@Transactional。我的web服务是这样注释的:
@WebService(targetNamespace = "http://my.domain.enote")
public interface IQueueWS {
@WebMethod(operationName="enqueueCandidate")
public List<String> enqueueCandidate(Candidate candidate);
@WebMethod(operationName="enqueueCandidates")
public List<String> enqueueCandidates(List<Candidate> candidates);
}
在我的实现类的顶部:
@Stateless
@WebService(
portName = "QueueWSPort",
serviceName = "QueueWSService",
targetNamespace = "http://gov.usdoj.afms.enote",
endpointInterface = "gov.usdoj.afms.enote.webservices.queue.IQueueWS")
public class QueueWS {
然后在客户端:
Service client = Service.create(
new URL("http://localhost:9080/eNotesApp/QueueWSService?wsdl"),
new QName("http://gov.usdoj.afms.enote", "QueueWSService"));
IQueueWS queue = client.getPort(IQueueWS.class);
Candidate c = new Candidate();
//blah blah, deleted for brevity
List<String> errors = queue.enqueueCandidate(c);
我曾经使用eclipse的wsgen向导来生成服务,所以这是我第一次尝试只使用注释。。。它们的工作范围使控制在正确的参数下达到需要的程度。正是这种交易性的东西阻碍了我们。
我认为@WebService
是事务性的原因是因为@Stateless
注释。在EJB 3.0中,所有EJB 3.0应用程序的默认事务属性都是REQUIRED。
如果你不想这样,你可以用为你的无状态会话bean类添加一个注释
@Stateless
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@WebService(
...
我认为这将使您能够在所描述的应用程序的较低级别中执行事务逻辑,并且不会启动全局事务。