I have a LocalContainerEntityManagerFactoryBean as EntityManager instance.
To quickly drop a full tables\' content, I want to run the follo
You should use TransactionTemplate object to manage transaction imperatively:
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus 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);