[
https://issues.apache.org/jira/browse/OPENJPA-2486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17172996#comment-17172996
]
chenlin edited comment on OPENJPA-2486 at 8/7/20, 9:03 AM:
-----------------------------------------------------------
Maybe you could add this @ExcludeSuperclassListeners on child
ps: javax.persistence.ExcludeSuperclassListeners comments,
(@ExcludeSuperclassListeners)
You can mask entity listeners declared in all parent classes of all current
entity classes.
was (Author: chenlin):
Maybe you could add this @ExcludeSuperclassListeners on chid
ps: javax.persistence.ExcludeSuperclassListeners comments,
(@ExcludeSuperclassListeners)
You can mask entity listeners declared in all parent classes of all current
entity classes.
> Unecessary @PreUpdate method call
> ---------------------------------
>
> Key: OPENJPA-2486
> URL: https://issues.apache.org/jira/browse/OPENJPA-2486
> Project: OpenJPA
> Issue Type: Bug
> Reporter: Alain Brazeau
> Priority: Major
>
> When a child is added to a parent in a bidirectional one-to-many association,
> the parent's @PreUpdate method gets called even when the parent does not
> require a database update.
> Here is a test I wrote in the 'openjpa-persistence-jdbc' project to
> demonstrate this issue:
> package org.apache.openjpa.persistence.jdbc.update;
> import java.util.Date;
> import javax.persistence.EntityManager;
> import org.apache.openjpa.persistence.test.SingleEMFTestCase;
> public class TestCascadePersist extends SingleEMFTestCase {
>
> public void setUp() throws Exception {
> super.setUp(CLEAR_TABLES, Parent.class, Child.class);
> }
>
> public void testAddChildShouldNotUpdateParent() {
> EntityManager em = emf.createEntityManager();
> em.getTransaction().begin();
> Parent parent = new Parent();
> parent.setName("parent");
> em.persist(parent);
> em.getTransaction().commit();
>
> long parentId = parent.getId();
> Date expectedLastModifiedDate = parent.getLastModifiedDate();
>
> em.getTransaction().begin();
> parent = em.find(Parent.class, parentId);
> parent.newChild("child");
> em.getTransaction().commit();
>
> Date actualModifiedDate = parent.getLastModifiedDate();
> assertEquals("The last modified date should not change.",
> expectedLastModifiedDate.getTime(),
> actualModifiedDate.getTime());
> }
> }
> In order for the test to work, the following instance variable and methods
> have to be added to the existing
> org.apache.openjpa.persistence.jdbc.update.Parent class:
> private Date lastModifiedDate;
>
> public Date getLastModifiedDate() {
> return lastModifiedDate;
> }
>
> @PrePersist
> @PreUpdate
> public void onUpdate() {
> this.lastModifiedDate = new Date();
> }
--
This message was sent by Atlassian Jira
(v8.3.4#803005)