2013-02-20 55 views
1

我正在將應用程序從GlassFish 3.1遷移到JBoss 6.1。IllegalArgumentException:無法將UserTransaction字段設置爲ServerVMClientUserTransaction

此代碼在GlassFish表現的很出色,但拋出一個醜陋的錯誤與JBoss:

自定義註釋:

@Named 
@ViewAccessScoped 
@Stereotype 
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) 
@Retention(RetentionPolicy.RUNTIME) 
public @interface Model {   
} 

豆:

@Model 
public class MyBean extends BaseBean { 

    @Inject 
    UserService userService 

    public void save() { 
     startTransaction(); 
     studioService.persist(studio); 
     commitTransaction(); 
    } 
} 

基地豆:

public class BaseBean implements Serializable { 

    @Resource 
    protected UserTransaction transaction; 
    @PersistenceContext(unitName = "fits_PU") 
    protected EntityManager entityManager; 
    [...] 

    protected void startTransaction() { 
     try { 
      transaction.begin(); 
      entityManager.joinTransaction(); 
     } catch [a few exceptions] 
    } 

    protected void commitTransaction() { 
     try { 
      transaction.commit(); 
     } catch [an awful lot of exceptions] 
    } 
} 

我得到以下異常:

Caused by: java.lang.IllegalArgumentException: Can not set javax.transaction.UserTransaction field my.company.project.BaseBean.transaction to org.jboss.tm.usertx.client.ServerVMClientUserTransaction 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164) [:1.7.0_11] 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168) [:1.7.0_11] 
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) [:1.7.0_11] 
    at java.lang.reflect.Field.set(Field.java:680) [:1.7.0_11] 

我已經整個下午谷歌搜索,但沒有找到任何線索開始。任何想法?

回答

0

所以。我環顧四周,嘗試了錯誤,發現我錯了。

如果我使用EJB,我不需要管理任何UserTransaction,因爲事務是由容器管理的。因此,

  1. 我在豆類去掉每一個參考吧
  2. 我改變了我的@Named服務到@Stateless EJB
  3. 我其注射到我的豆與@EJB註釋,而不是@Inject

希望它能幫助別人。

相關問題