I am trying to change the id of an persisted object .I am using JPA with Hibernate and MySQL. The error I get when executing my code is : org.hibernate.HibernateException: identifier of an instance of com.tutorial.jpa.certification.listing5_18.AA was altered from 2 to 99
I couldn't find an answer to this problem so I would appreciate your help here.The code is:
EntityManagerFactory emf=Persistence.createEntityManagerFactory("Tutorial");
EntityManager em=emf.createEntityManager();
AA aa=em.find(AA.class, 2);
em.getTransaction().begin();
aa.setId(99);
em.merge(aa);
em.getTransaction().commit();