Using @TransactionAttribute (value = TransactionAttributeType.NEVER) for a method

Is it possible to call a method that requires a transaction inside a method that does not support?

@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

}

The .NEVER attribute says that it guarantees that the method is not executed inside the transaction, but as for calls to other methods inside this method.

+5
source share
1 answer

, ( ). , . , - .

, , NEVER. , . MANDATORY, , , MANDATORY .

+9

All Articles