@Configurable public class AuditingEntityListener<T> extends Object implements InitializingBean
orm.xml
as follows:
<persistence-unit-metadata> <persistence-unit-defaults> <entity-listeners> <entity-listener class="org.springframework.data.jpa.domain.auditing.support.AuditingEntityListener" /> </entity-listeners> </persistence-unit-defaults> </persistence-unit-metadata>After that it's just a matter of activating auditing in your Spring config:
<jpa:auditing auditor-aware-ref="yourAuditorAwarebean" />
Constructor and Description |
---|
AuditingEntityListener() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
void |
setAuditorAware(org.springframework.data.domain.AuditorAware<T> auditorAware)
Setter to inject a
AuditorAware component to retrieve the current auditor. |
void |
setDateTimeForNow(boolean dateTimeForNow)
Setter do determine if
Auditable.setCreatedDate(DateTime) and
Auditable.setLastModifiedDate(DateTime) shall be filled with the current Java time. |
void |
setDateTimeProvider(DateTimeProvider dateTimeProvider)
Sets the
DateTimeProvider to be used to determine the dates to be set. |
void |
setModifyOnCreation(boolean modifyOnCreation)
Set this to false if you want to treat entity creation as modification and thus set the current date as
modification date, too.
|
void |
touchForCreate(Object target)
Sets modification and creation date and auditor on the target object in case it implements
Auditable on
persist events. |
void |
touchForUpdate(Object target)
Sets modification and creation date and auditor on the target object in case it implements
Auditable on
update events. |
public void setAuditorAware(org.springframework.data.domain.AuditorAware<T> auditorAware)
AuditorAware
component to retrieve the current auditor.auditorAware
- the auditorAware to setpublic void setDateTimeForNow(boolean dateTimeForNow)
Auditable.setCreatedDate(DateTime)
and
Auditable.setLastModifiedDate(DateTime)
shall be filled with the current Java time. Defaults to
true
. One might set this to false
to use database features to set entity time.dateTimeForNow
- the dateTimeForNow to setpublic void setModifyOnCreation(boolean modifyOnCreation)
true
.modifyOnCreation
- if modification information shall be set on creation, toopublic void setDateTimeProvider(DateTimeProvider dateTimeProvider)
DateTimeProvider
to be used to determine the dates to be set.dateTimeProvider
- public void touchForCreate(Object target)
Auditable
on
persist events.target
- public void touchForUpdate(Object target)
Auditable
on
update events.target
- public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
Copyright © 2011-2012-2012 SpringSource. All Rights Reserved.