Community
Participate
Working Groups
Created attachment 243167 [details] Test Case EclipseLink We want to create a new entity. We call merge on entity , @Prepersist is called but changed are not applied to entity. Please Note: * When i call persist on entity prepersist is called and changes are applied! Related to this i can make such conclusion: - prepersist works when i call a persist on entity - preupdate works when i call a merge on entity - prepersist DOESN'T work when i call merge on a new entity!!! Below i provided a test Case application. Test app.
This is not a bug. The prepersist is called on the managed entity, which has the changes made to it, and then the merge is applied. The problem with your test case is that you are modifying a relationship in the prepersist. The merge will cause this change to be overriden with null. This works differently in the other cases: When calling persist, the entity passed in is used for the prepersist, so the persist will pick up the change. When using merge and preupdate, the preUpdate happens after the merge. PreUpdate is tied to the database operation, not the JPA merge operation.
The specification states the in section 3.5.2 "For entities to which the merge operation has been applied and causes the creation of newly managed instances, the PrePersist callback methods will be invoked for the managed instance after the entity state has been copied to it." This should be expected to work, and I am reopening for investigation.
What is the status of the issue? could i recieve a patch?
For me this problem occurs too, I have an entity with a Listener for with an @PreUpdate annoted method, the @PreUpdate method never is called, the workaround to avoid the problem is to call the listener method before calling merge. I'm using Tomcat and Jersey with a REST API and EclipseLink as the JPA engine. here the snippets: 1) from REST call @POST @Path("{id}") @Consumes({ "application/xml", "application/json"}) public void edit(@PathParam("id") Integer id, Usuario entity) { //TODO: waiting solution of BUG https://bugs.eclipse.org/bugs/show_bug.cgi?id=435044 UsuarioListener usuarioListener = new UsuarioListener(); usuarioListener.atualizaDados(entity); super.edit(entity); } 2) The super implementation edit method public void edit(T entity) { em.getTransaction().begin(); ((Persistable) entity).refreshReferences(em); em.merge(entity); em.getTransaction().commit(); }
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink