我正在将应用程序从 GlassFish 3.1 迁移到 JBoss 6.1。
这段代码在 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]
我整个下午都在谷歌上搜索它,但找不到任何开始的提示。任何想法?