You should use TransactionTemplate
object to manage transaction imperatively:
transactionTemplate.execute(
status -> em.createNativeQuery("TRUNCATE TABLE MyTable").executeUpdate());
To create TransactionTemplate
just use injected PlatformTransactionManager
:
transactionTemplate = new TransactionTemplate(platformTransactionManager);
And if you want to use new transaction just invoke
transactionTemplate.setPropagationBehavior(
TransactionDefinition.PROPAGATION_REQUIRES_NEW);