メソッド内でトランザクションを必要とするメソッドを呼び出すことはできますか?メソッドの@TransactionAttribute(value = TransactionAttributeType.NEVER)の使用
@TransactionAttribute(value = TransactionAttributeType.NEVER)
public void DoSomething(final List<Item> items) {
//can you call a method that requires a transaction here ?
for (Item i : items) {
methodCall(item);
}
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void methodCall(final Item item) {
// access lazily loaded item properties
item.getSalesOrder();
item.getAllocation();
//throws org.hibernate.LazyInitializationException: could not initialize proxy - no Session
}
.NEVER属性は、それがその方法
@TransactionAttributeアノテーションをクラスレベルで適用して、エンタープライズBeanのすべてのビジネスメソッドのデフォルトのトランザクション属性を指定することができます。この注釈をメソッドレベルで適用して、そのメソッドのトランザクション属性を指定することができます。アノテーションをメソッドレベルで適用すると、そのメソッドのクラスレベルアノテーション(存在する場合)がオーバーライドされます。 – Luke