📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
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();
}
Comments
Post a Comment
Leave Comment