Spring Data Jpa

org.springframework.data.jpa.domain.support
Class AuditingEntityListener<T>

java.lang.Object
  extended by org.springframework.data.jpa.domain.support.AuditingEntityListener<T>
All Implemented Interfaces:
InitializingBean

@Configurable
public class AuditingEntityListener<T>
extends Object
implements InitializingBean

JPA entity listener to capture auditing information on persiting and updating entities. To get this one flying be sure you configure it as entity listener in your 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" />
 

Author:
Oliver Gierke

Constructor Summary
AuditingEntityListener()
           
 
Method Summary
 void afterPropertiesSet()
           
 void setAuditorAware(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditingEntityListener

public AuditingEntityListener()
Method Detail

setAuditorAware

public void setAuditorAware(AuditorAware<T> auditorAware)
Setter to inject a AuditorAware component to retrieve the current auditor.

Parameters:
auditorAware - the auditorAware to set

setDateTimeForNow

public void setDateTimeForNow(boolean dateTimeForNow)
Setter do determine if 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.

Parameters:
dateTimeForNow - the dateTimeForNow to set

setModifyOnCreation

public 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. Defaults to true.

Parameters:
modifyOnCreation - if modification information shall be set on creation, too

setDateTimeProvider

public void setDateTimeProvider(DateTimeProvider dateTimeProvider)
Sets the DateTimeProvider to be used to determine the dates to be set.

Parameters:
dateTimeProvider -

touchForCreate

public void touchForCreate(Object target)
Sets modification and creation date and auditor on the target object in case it implements Auditable on persist events.

Parameters:
target -

touchForUpdate

public void touchForUpdate(Object target)
Sets modification and creation date and auditor on the target object in case it implements Auditable on update events.

Parameters:
target -

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

Spring Data Jpa

Copyright © 2011-2012-2012 SpringSource. All Rights Reserved.