Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Application Server  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求助:Jboss下调用ejb的create方法作数据插入出错
susanjin



发贴: 0
积分: 0
于 2003-03-19 10:45 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在ejb的create方法中插入一条数据,并取出主键的值,代码如下:
String sql="insert into questionTopic(name,parentId,description) values(?,?,?)";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1,this.name);
...
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();
运行后,抛出的错误如下:
javax.transaction.RollbackException: Unable to commit, tx=XidImpl [FormatId=257, GlobalId=jinshusa//5, BranchQual=] status=STATUS_ROLLEDBACK
......
我试了一下,如果这段程序单独在一个普通的java程序中运行则一切正常,请问这是什么原因?是不是和jboss的配置有关?



作者 Re:求助:Jboss下调用ejb的create方法作数据插入出错 [Re:susanjin]
Big Blue



版主


发贴: 601
积分: 121
于 2003-03-19 14:00 user profilesend a private message to usersend email to Big Bluesearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
贴出你较完整的src


作者 Re:求助:Jboss下调用ejb的create方法作数据插入出错 [Re:susanjin]
susanjin



发贴: 0
积分: 0
于 2003-03-19 15:59 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
通过一个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的那段去掉,也会抛出一样的错误。真是不明白。



作者 这是我的配置文件(mssql-service.xml) [Re:susanjin]
susanjin



发贴: 0
积分: 0
于 2003-03-19 16:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.resource.connectionmanager.LocalTxConnectionManager" name="jboss.jca:service=LocalTxCM,name=MSSQLDS">

<!--uncomment out this line if you are using the MSSQLDbRealm above
<attribute name="SecurityDomainJndiName">MSSQLDbRealm</attribute>
-->

<depends optional-attribute-name="ManagedConnectionFactoryName">
<!--embedded mbean-->
<mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=MSSQLDS">

<attribute name="JndiName">MSSQLDS</attribute>

<attribute name="ManagedConnectionFactoryProperties">
<properties>
<config-property name="ConnectionURL" type="java.lang.String">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Testing</config-property>
<config-property name="DriverClass" type="java.lang.String">com.microsoft.jdbc.sqlserver.SQLServerDriver</config-property>
<!--set these only if you want only default logins, not through JAAS-->
<config-property name="UserName" type="java.lang.String">sa</config-property>
<config-property name="Password" type="java.lang.String"></config-property>
</properties>
</attribute>

<!--Below here are advanced properties -->
<!--hack-->
<depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper</depends>
</mbean>
</depends>

<depends optional-attribute-name="ManagedConnectionPool">
<!--embedded mbean-->
<mbean code="org.jboss.resource.connectionmanager.JBossManagedConnectionPool" name="jboss.jca:service=LocalTxPool,name=MSSQLDS">
<attribute name="MinSize">0</attribute>
<attribute name="MaxSize">50</attribute>
<attribute name="BlockingTimeoutMillis">5000</attribute>
<attribute name="IdleTimeoutMinutes">15</attribute>
<!--criteria indicates if Subject (from security domain) or app supplied
parameters (such as from getConnection(user, pw)) are used to distinguish
connections in the pool. Choices are
ByContainerAndApplication (use both),
ByContainer (use Subject),
ByApplication (use app supplied params only),
ByNothing (all connections are equivalent, usually if adapter supports
reauthentication)-->
<attribute name="Criteria">ByContainer</attribute>
</mbean>

</depends>
<depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager</depends>

<depends optional-attribute-name="JaasSecurityManagerService">jboss.security:service=JaasSecurityManager</depends>

<attribute name="TransactionManager">java:/TransactionManager</attribute>
<!--make the rar deploy! hack till better deployment-->
<depends>jboss.jca:service=RARDeployer</depends>

</mbean>

</server>



作者 Re:求助:Jboss下调用ejb的create方法作数据插入出错 [Re:susanjin]
gunrose





发贴: 100
积分: 20
于 2003-03-20 10:44 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我的看法:
第一:at com.dynasty.testing.test.TestContentSBTestClient1.main(TestContentSBTestClient1.java:141)你的141行是什么代码?是connection本身出了问题,还是create出了问题?

第二:不建议在每次调用ejbCreate的时候创建DAO,除非你的DAO本身做了cache,否则会很慢.

第三:是否有可能jboss的connection默认是rollback,而不是commit?试试加上在最后加上commit看看.

反正是瞎猜,也不知道能否帮上忙



作者 Re:求助:Jboss下调用ejb的create方法作数据插入出错 [Re:susanjin]
susanjin



发贴: 0
积分: 0
于 2003-03-21 09:38 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
谢谢各位的帮忙,问题已经解决。另外,有个问题请教gunrose,关于你的第二点建议,那么你的建议是什么?怎么才能提高效率呢?


作者 Re:求助:Jboss下调用ejb的create方法作数据插入出错 [Re:susanjin]
Big Blue



版主


发贴: 601
积分: 121
于 2003-03-21 09:54 user profilesend a private message to usersend email to Big Bluesearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
是什么原因?



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923