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:
Joined: Aug 28, 2006
More over, If the entity doesn't existing in the database, I think the system throws Entity doesn't existing exception upon deleting the entity rather than the exception I posted earlier.
Joined: Aug 28, 2006
Hi E Lievaart, It is working fine If I am using the following method instead of merge:
And another thing is that, I have a manager entity which has one-to-many relation with the employee. followig is the code:
If I am trying to delete the manager useing the following code, it simply working fine but the same code is not working for the employee entity.
can you throw some light on it?
Joined: Jul 06, 2008
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 ]