susanjin
发贴: 0
积分: 0
|
于 2003-03-19 15:59
通过一个entitybean(BMP)的create方法插入一条数据,具体的插入实现是通过调用一个名为QuestionTopicDAO的普通类的insert方法来操作的,具体的代码如下: EJB中的ejbCreate方法: public Long ejbCreate(String name,long parentId,String description) throws CreateException { /**@todo Implement this method*/ this.name=name; this.parentId=parentId; this.description=description; QuestionTopicDAO QTDAO=new QuestionTopicDAO(name,parentId,description); try{ dbConn=this.getDBConnection(); QTDAO.insert(dbConn); id=QTDAO.getId(); }catch(SQLException se){ throw new CreateException ("SQL Exception in create:" + se); }finally { try { dbConn.close(); } catch (SQLException se) { throw new CreateException("SQL Exception in create:" + se); } }
QuestionTopicDAO中的insert方法: public void insert() throws SQLException{ String sql="insert into questionTopic(name,parentId,description) values(?,?,?)"; PreparedStatement ps=conn.prepareStatement(sql); ps.setString(1,this.name); ps.setLong(2,this.parentId); ps.setString(3,this.description); ps.executeUpdate(); ps.close(); sql="select max(id) from questionTopic"; ps=conn.prepareStatement(sql); ResultSet rs=ps.executeQuery(); if(rs.next()) this.id=rs.getLong(1); rs.close(); ps.close(); }
数据库的驱动用的是Microsoft SQL Server 2000 Driver for JDBC,在jboss的mssql-xa-service.xml和mssql-service.xml都作了配置。
当通过一个客户端的普通java程序条用该ejb的create方法,就会抛出如下错误: javax.transaction.RollbackException: Unable to commit, tx=XidImpl [FormatId=257, GlobalId=jinshusa//3, BranchQual=] status=STATUS_ROLLEDBACK
at org.jboss.tm.TxCapsule.commit(TxCapsule.java:425)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:73)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:201)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:313)
at org.jboss.ejb.Container.invoke(Container.java:712)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:382)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:536)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)
at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:138)
at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:108)
at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)
at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:111)
at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
at $Proxy1.createQuestionTopic(Unknown Source)
at com.dynasty.testing.test.TestContentSBTestClient1.main(TestContentSBTestClient1.java:141)
不知道是什么原因,就算是把插入程序中的那段选取最大ID的那段去掉,也会抛出一样的错误。真是不明白。
|