EntityTransaction Interface Overview
EntityTransaction Interface Methods
- void begin() - Start a resource transaction.
- void commit() - Commit the current resource transaction, writing any unflushed changes to the database.
- boolean getRollbackOnly() - Determine whether the current resource transaction has been marked for rollback.
- boolean isActive() - Indicate whether a resource transaction is in progress.
- void rollback() - Roll back the current resource transaction.
- void setRollbackOnly() - Mark the current resource transaction so that the only possible outcome of the transaction is for the transaction to be rolled back.
EntityTransaction Interface Example
private static void insertEntity() {
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("PERSISTENCE");
EntityManager entityManager = entityManagerFactory.createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
Student student = new Student("Ramesh", "Fadatare", "rameshfadatare@javaguides.com");
entityManager.persist(student);
entityManager.getTransaction().commit();
entityManager.close();
entityManagerFactory.close();
}
Related Posts
Reference
Continue Learning with Java Guides
Want to take your programming skills to the next level? Explore my practical Udemy courses on Java, Spring Boot, Microservices, Full-Stack Development, Docker, and Generative AI. You can also follow my structured learning roadmaps to become a professional developer.
By Ramesh Fadatare - Udemy Instructor Partner

Comments
Post a Comment
Leave Comment