I'm persisting two entities, the second one has a unique constraint but when I try to break that constraint a javax.persistence.RollbackException: Transaction marked as rollbackOnly is thown so the first persisted entity is not rolled back. Im using the @Transactional Spring annotation, anyway here is the code , I'd appreciate very much any help :
Spring application context : . . <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Service class method:
Image i= new Image(); i.setImagePath("asdfads"); Book b= new Book(); b.setTitle("aaa"); try { //entityManager.persist(presInd); //entityManager.persist(verbo); entityManager.persist(i); entityManager.persist(b); //throw new java.lang.Exception(); return true; } catch (Exception e) { // TODO: handle exception System.out.println(e.getMessage()); System.out.println("calling rooback");
Exception : javax.persistence.RollbackException: Transaction marked as rollbackOnly
|