Search code examples
javajpaeclipselink

is it possible to update entity with out setters being called in jpa


I am working on application, which has an entity called My.java, it is extending from another entity which has field called edited. This field will be updated with current time stamp, for each update

I am using single table inheritance strategy.

I am using jpa/eclipse link as persistance provider.

edited field is updating with current time stamp even with out setter method called, there are no other references in my java code changing the value of this edited field.

While debugging I can see UPDATE QL statement, for edited field update.

I am really wondering why/how it's value updating, it it possible with out setter invocation?

Here is the mapped super class:

  @MappedSuperclass

public abstract class SuperEntity implements  Serializable {    

/**
 * 
 */
private static final long serialVersionUID = 1125783654888232605L;
/**
 * The time the entry was created
 */
@Column(name = "CREATED")
private Timestamp created;
/**
 * The date the entry was edited
 */
@Column(name = "EDITED")
@Version
private Timestamp edited;

Solution

  • Check these things.

    1. Your entity may be implementing some kind of auditable interface
    2. Your field may be having @Version annotation

    In 1st case you have figure out that interface usage and you can understand it In 2nd case it's the default and expected behavior in EJB and Hibernate.

    I got this link after googling it may be useful for you

    https://technology.amis.nl/2006/01/03/ejb-30-persistence-using-the-version-annotation-for-optimistic-locking-in-the-glassfish-reference-implementation/

    It's not a big worry thing, you can get over it easily