Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » AuditingEntityListener - updating on child add
AuditingEntityListener - updating on child add [message #1461624] Tue, 04 November 2014 19:21
adam green is currently offline adam greenFriend
Messages: 1
Registered: November 2014
Junior Member
I have a simple parent child object relationship.
The child is the owner of the relationship as the parent has the "mappedby" attribute set of the OneToMany Annotation.

The parent is pre existing in the database.
In a single transaction, I load the parent, create a new child, set the parent on the child and add the child to the parent's IndirectList.

The child is then saved.

Now this "works" however the parent has a Date field annotated with @LastModifiedDate.

public class StoreCardInstance implements Serializable {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idStoreCardInstance")
    @Getter @Setter
    private Integer idStoreCardInstance;
    @Basic(optional = false)
    @Column(name = "updateDateTime")
    @Getter @Setter
    private Date updateDateTime;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "storeCardInstance")
    @Getter @Setter
    private Collection<UserStoreCardInstance> userStoreCardInstanceCollection;

    public StoreCardInstance addUserStoreCardInstanceInstance(@NonNull UserStoreCardInstance userStoreCardInstance){
            this.userStoreCardInstanceCollection = new ArrayList<>();
        return this;

public class UserStoreCardInstance implements Serializable {
    private static final long serialVersionUID = 1L;
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idUserStoreCardInstance")
    @Getter @Setter
    private Integer idUserStoreCardInstance;
    @JoinColumn(name = "storeCardInstance", referencedColumnName = "idStoreCardInstance")
    @Getter @Setter
    private StoreCardInstance storeCardInstance;


For some reason, the parent is updated with a new last modified date when saving the parent. It seems to think the parent is dirty but nothing has changed with the exception that the child has been added to the collection.

Where I am having trouble is if I run the code as a "main" class (with the exact same spring application context configuration) the code works as expected and only the new child is created.
If the code is run as part of a web application (either using Jetty or Tomcat 7/8) then the parent date time field is updated.

I am trying to prepare a simple unit test and some code examples, but this difference between running in and outside of a web application is making it very difficult to get a simple test case to illustrate the problem.

Using the latest Eclipse link (2.5.2) and spring (4.1.1)

Any help appreciated

Previous Topic:Possible bug retrieving single Boolean column
Next Topic:Orderby NULL FIRST / LAST using Criteria API
Goto Forum:

Current Time: Sun Jul 21 21:04:46 GMT 2024

Powered by FUDForum. Page generated in 0.03667 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top