beginTransaction
メソッドをコールしようとすると、次のコードでNullポインター例外が発生します。私はJBossが私のトランザクションを開始すると思った...明らかにそうではない:\JBoss - ユーザートランザクションが挿入されていません
私は何が欠けていますか?
のJBoss 5.1.0.GA
JPA 1
JDK 6
import javax.annotation.Resource;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.transaction.UserTransaction;
public abstract class AbstractDAO {
@PersistenceUnit(unitName = "miniDS")
protected static EntityManagerFactory emf;
@Resource
protected UserTransaction t;
public AbstractDAO() {
}
protected void beginTransaction() throws Throwable {
t.begin();
}
protected void commitTransaction() throws Throwable {
t.commit();
}
protected void rollbackTransaction() throws Throwable {
t.rollback();
}
}
SpringのtransactionManagerを通じて、DAOを使用しているサービスで@Transactionalアノテーションを使用できます。 これは、トランザクションの開始/終了を自動的に処理します。 – bugske