Search in sources :

Example 1 with Timestamped

use of com.spaceprogram.simplejpa.model.Timestamped in project simplejpa by appoxy.

the class SomeEntityListener method preUpdate.

@PreUpdate
public void preUpdate(Object object) {
    System.out.println("preUpdate.");
    if (object instanceof Timestamped) {
        System.out.println("Setting timestamps.");
        Timestamped timestamped = (Timestamped) object;
        timestamped.setUpdated(new Date());
    }
}
Also used : Timestamped(com.spaceprogram.simplejpa.model.Timestamped) Date(java.util.Date) PreUpdate(javax.persistence.PreUpdate)

Example 2 with Timestamped

use of com.spaceprogram.simplejpa.model.Timestamped in project simplejpa by appoxy.

the class SomeEntityListener method prePersist.

@PrePersist
public void prePersist(Object object) {
    System.out.println("prePersist");
    if (object instanceof Timestamped) {
        System.out.println("Setting timestamps.");
        Timestamped timestamped = (Timestamped) object;
        Date now = new Date();
        timestamped.setCreated(now);
        timestamped.setUpdated(now);
    }
}
Also used : Timestamped(com.spaceprogram.simplejpa.model.Timestamped) Date(java.util.Date) PrePersist(javax.persistence.PrePersist)

Aggregations

Timestamped (com.spaceprogram.simplejpa.model.Timestamped)2 Date (java.util.Date)2 PrePersist (javax.persistence.PrePersist)1 PreUpdate (javax.persistence.PreUpdate)1