Hello all,
I'm testing programmatically manage transaction using the example here
http://static.springframework.org/sp...ogrammatic-ptm
What's not clear to me is how to perform the middle part between the transaction.Code:DefaultTransactionDefinition def = new DefaultTransactionDefinition(); // explicitly setting the transaction name is something that can only be done programmatically def.setName("SomeTxName"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txManager.getTransaction(def); try { // execute your business logic here } catch (MyException ex) { txManager.rollback(status); throw ex; } txManager.commit(status);
I tried
Looking at the log files, no insert statement was logged, no errors/exceptions.Code:@PersistenceUnit(unitName = "springappPU") private EntityManagerFactory emf; public void setEntityManagerFactory(EntityManagerFactory emf) { this.emf = emf; } private EntityManager getEntityManager() { return emf.createEntityManager(); } PlatformTransactionManager txnManager = null; public void setTxnManager(PlatformTransactionManager mgr){ txnManager = mgr; } ..... try { EntityManager em = this.getEntityManager(); em.persist(sponsor); } catch (MyException ex) { txManager.rollback(status); throw ex; } txManager.commit(status);
I also tried to get EntityManager by
same issue, no insert, no errors, no exceptionsCode:EntityManager em = txnManager.getEntityManagerFactory().createEntityManager();
what am I doing wrong?
Thanks


Reply With Quote