I have the following code:
package testingjpa;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
public class Main
{
public static void main(String[] args)
{
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("TestingJPAPU");
EntityManager em = emFactory.createEntityManager();
Query query = em.createQuery("UPDATE Passengers p SET p.name = 'Robert' WHERE p.id = 2");
query.executeUpdate();
em.close();
}
}
The problem with this code is that it is throwing a TransactionRequiredException. The entity class works fine since I have tried using other code and it worked perfectly. How can I solve this problem please?
1 Answer