Search in sources :

Example 1 with PreUpdate

use of javax.persistence.PreUpdate 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 PreUpdate

use of javax.persistence.PreUpdate in project wildfly by wildfly.

the class LastUpdateListener method setLastUpdate.

@PreUpdate
@PrePersist
public void setLastUpdate(Cat o) {
    o.setLastUpdate(new Date());
    o.setManualVersion(o.getManualVersion() + 1);
}
Also used : Date(java.util.Date) PrePersist(javax.persistence.PrePersist) PreUpdate(javax.persistence.PreUpdate)

Example 3 with PreUpdate

use of javax.persistence.PreUpdate in project wildfly by wildfly.

the class MyListener method onEntityCallback.

@PrePersist
@PreUpdate
public void onEntityCallback(Object entity) {
    try {
        invocationCount++;
        InitialContext jndiContext = new InitialContext();
        EJBContext ctx = (EJBContext) jndiContext.lookup("java:comp/EJBContext");
    //System.out.println(ctx.getCallerPrincipal().getName() + ", entity=" + entity);
    } catch (NamingException e) {
        throw new RuntimeException("initial context error", e);
    }
}
Also used : EJBContext(javax.ejb.EJBContext) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) PrePersist(javax.persistence.PrePersist) PreUpdate(javax.persistence.PreUpdate)

Example 4 with PreUpdate

use of javax.persistence.PreUpdate in project simplejpa by appoxy.

the class TimestampEntityListener method preUpdate.

@PreUpdate
public void preUpdate(Object object) {
    if (object instanceof Timestamped) {
        Timestamped timestamped = (Timestamped) object;
        timestamped.setUpdated(new Date());
    }
}
Also used : Date(java.util.Date) PreUpdate(javax.persistence.PreUpdate)

Example 5 with PreUpdate

use of javax.persistence.PreUpdate in project hibernate-orm by hibernate.

the class LastUpdateListener method setLastUpdate.

@PreUpdate
@PrePersist
public void setLastUpdate(Cat o) {
    o.setLastUpdate(new Date());
    o.setManualVersion(o.getManualVersion() + 1);
}
Also used : Date(java.util.Date) PrePersist(javax.persistence.PrePersist) PreUpdate(javax.persistence.PreUpdate)

Aggregations

PreUpdate (javax.persistence.PreUpdate)6 Date (java.util.Date)4 PrePersist (javax.persistence.PrePersist)3 Timestamped (com.spaceprogram.simplejpa.model.Timestamped)1 EJBContext (javax.ejb.EJBContext)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1