I am learning JPA Entity life cycle and i want to understand the 'Detached' entities. Below is my code,
//Creating a new employee with id and name field
Employee e = new Employee("1001","Sasi");
em.getTransaction().begin();
em.persist(e);
em.getTransaction().commit();
//Detaching Employee from Persistence context
em.detach(e);
//Persisting detached entity
em.getTransaction().begin();
e.setEmployeeId("1002");
em.persist(e);
em.getTransaction().commit();
What i am seeing is, there are two rows inserted in to mysql database instead of getting an error. Could you please let me know why error is not thrown? I am sure that i misunderstood the concept of detached entities and kindly help me in understanding it correctly.