Hi all,
I have a scenario where I have a Department entity, and then wish to delete it.
I thought that I should be able to create a new Department instance and set
its primary key to that of the department I wish to delete, and then merge that
entity and remove it:
__
EntityManager em = getEntityManager();
Department newdepartment = new Department();
newdepartment.setDeptno("1234");
em.getTransaction().begin();
Department department = em.merge(newdepartment);
em.remove(department);
em.getTransaction().commit();
__
This code executes but does not remove the specific entity. From reading the
JPA spec, I thought that if there is no version field on the entity, then the
merge() call will look for an entity that has the same ID (primary key) as the
instance you pass in. So I thought that the above code would work.
If instead of creating a new instance I retrieve the entity via find():
department = (Department) em.find(Department.class, "1234");
Then it is removed properly as expected. Does anyone know if the above code
should work, or if I have just misinterpreted the spec?
Thanks
Tom