use of javax.persistence.PrePersist 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);
}
}
use of javax.persistence.PrePersist in project simplejpa by appoxy.
the class TimestampEntityListener method prePersist.
@PrePersist
public void prePersist(Object object) {
if (object instanceof Timestamped) {
Timestamped timestamped = (Timestamped) object;
Date now = new Date();
timestamped.setCreated(now);
timestamped.setUpdated(now);
}
}
use of javax.persistence.PrePersist 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);
}
use of javax.persistence.PrePersist in project CzechIdMng by bcvsolutions.
the class AuditableEntityListener method touchForCreate.
/**
* Sets creation date and creator on the target object in case it implements {@link Auditable} on
* persist events.
*
* @param target
*/
@PrePersist
public void touchForCreate(Object target) {
if (target instanceof Auditable) {
AutowireHelper.autowire(this, this.securityService);
//
DateTime date = new DateTime();
Auditable entity = (Auditable) target;
//
if (entity.getCreated() == null) {
entity.setCreated(date);
}
//
AbstractAuthentication authentication = securityService.getAuthentication();
IdmIdentityDto currentIdentity = authentication == null ? null : authentication.getCurrentIdentity();
IdmIdentityDto originalIdentity = authentication == null ? null : authentication.getOriginalIdentity();
if (entity.getCreator() == null) {
String creator = currentIdentity == null ? securityService.getUsername() : currentIdentity.getUsername();
entity.setCreator(creator);
//
UUID creatorId = currentIdentity == null ? null : currentIdentity.getId();
entity.setCreatorId(creatorId);
}
// could be filled in wf (applicant) ...
if (entity.getOriginalCreator() == null) {
String originalCreator = originalIdentity == null ? null : originalIdentity.getUsername();
entity.setOriginalCreator(originalCreator);
//
UUID originalCreatorId = originalIdentity == null ? null : originalIdentity.getId();
entity.setOriginalCreatorId(originalCreatorId);
}
}
}
use of javax.persistence.PrePersist in project plumdo-work by wengwh.
the class BaseEntity method prePersist.
@PrePersist
public void prePersist() {
this.createTime = new Timestamp(new Date().getTime());
this.lastUpdateTime = this.createTime;
}
Aggregations