你能在不需要事务的方法中调用需要事务的方法吗?
.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属性表示该方法不会在事务中运行,但是对于该方法内部调用其他方法呢?