请教CMP并发访问时的事务问题

04-08-04 kgd924

2004-08-04 17:35:37,656 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackLocalException in method: public abstract void org.glide.ejbglide.Student.setAid_code_id(java.lang.String), causedBy:

org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl [FormatId=257, GlobalId=kgd//472865, BranchQual=] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=2id=1091612137375)

at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:413)

关键代码如下:

while(iter.hasNext())

{

org.glide.data.Student studata=(org.glide.data.Student)iter.next();

try {

org.glide.ejbglide.Student stucmp = stuHome.create(Long.toString(System.currentTimeMillis()));

stucmp.setAid_code_id(studata.getAid_code_id());

stucmp.setBIRTHDAY(studata.getBirthday());

stucmp.setDISTRICT_CODE(studata.getDistrict_code());

我只是简单向数据库中插入数据。为什么多个人并发访问的时候就会出现上面的异常呢?

banq
2004-08-10 12:50

你这段代码需要在Session Bean中执行。

不要在while中操作过长。可使用CMP的批量更新语句。