Esistono diverse strategie di propagazione delle transazioni da utilizzare. Questi esistono nell'enum Propagation
. Quelli che potresti voler usare sono
/**
* Execute non-transactionally, suspend the current transaction if one exists.
* Analogous to EJB transaction attribute of the same name.
* <p>Note: Actual transaction suspension will not work on out-of-the-box
* on all transaction managers. This in particular applies to JtaTransactionManager,
* which requires the {@code javax.transaction.TransactionManager} to be
* made available it to it (which is server-specific in standard J2EE).
* @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager
*/
NOT_SUPPORTED(TransactionDefinition.PROPAGATION_NOT_SUPPORTED),
/**
* Execute non-transactionally, throw an exception if a transaction exists.
* Analogous to EJB transaction attribute of the same name.
*/
NEVER(TransactionDefinition.PROPAGATION_NEVER), // maybe not this one
Quindi annota il metodo all'interno della tua classe con uno di questi.
@Transactional
public class MyTransactionalClass {
@Transactional(propagation = PROPAGATION_NOT_SUPPORTED)
public void nonTransactionalMethod() {...}
}
È possibile trovare tutte le strategie di propagazione here.
fonte
2013-08-14 15:09:24
hai provato '@Transactional (propagation = NOT_SUPPORTED)'? –