When excecuting the above client, I am getting the following exception: javax.persistence.EntityNotFoundException: deleted entity passed to persist: [bala.persistent.Employee#<null>] (same the case with sateless session bean in the above case)
If I make the following change for PersistenceContext it works fine: @PersistenceContext(type=PersistenceContextType.EXTENDED)
If you observe closely my client code. I am printing the company name after the retrieval of the company entity from the database. It works simply fine if I am changing the persistent context type to extended. I am posting the Employee Bean:
My best guess here is that you get the exception due to a FK constraint. In JPA it is the programmers job to ensure the references are valid. Try setting the references to null after you merge, before you remove. So set Employee.manager to null and remove the Employee from Manager.employees.
I finally got an exception. Let me explain what I did.
At the beginning my client was doing the following: 1) Insert manager 2) Insert employee 3) Delete employee 4) Delete manager
Everething in the same client execution: I did not get any errors.
At a given time and after trying several combinations, I got the following exception: javax.persistence.EntityExistsException (Cannot persist detached object). This is what I did: 1) Insert the manager 2) Insert the client 3) Delete the client At this point my client execution finished, and in the next execution I tried to: 4) Insert the client ---> EntityExistsException
it works fine after changing the bean in the following way:
I also needed to implement the equals() method in the Employee class (to make List.remove() work properly);
Try the changes I am proposing and tell me if it works OK. [ July 22, 2008: Message edited by: Sergio Tridente ]