This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hello I am using Tomlink JPA as persistence provider for EJB3.
The problem has raised when I tried to remove some entities from a collection. As I have some exprience in Hibernate, I thought all the details entities will be removed when I remove them from the collection but soon I realized that in TopLink this is not the case.
now I am removing the entities individually, but the problem is that it seems the entity manager has removed the entities I declared but in database all the records are exists!!!
More stranger, in next execution the deleted entities are not loaded and everything seems ok but if I restart the application server all the removed data is coming back!!
after removing the entity I called entityManager.flush() and even I put TransactionAttribute for the value of REQUIRES_NEW but nothing has changed.
after toiling, I found that if I remove the REQUIRES_NEW from the delete() method of my DAO that works fine. Would anyone explain me what happens here? As I have read, if you put REQUIRES_NEW the new transaction will start for that method and after exiting the method the transaction will be committed so my assumption is the data is visible to other transaction when it is going to read the same data (including removed records) but this is quite different from my understanding?
The EntityManager caches object queries. I think you have to call em.refresh on the parent object to signify that a child of his was deleted in the database for finder methods or set a query hint for query methods.
For finder methods :
Lets say we have Object A (parent) which holds a collection of Object B. If you remove one instance of Object B then query Object A, the EntityManager will give you the same number of Object B, unless you query Object A and force a synchronization by calling em.refresh on Object A for finder methods.