deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nico Schlebusch <>
Subject DeltaSpike Data - Custom PrePersistAuditListener and PreUpdateAuditListener
Date Wed, 07 Dec 2016 10:22:26 GMT
Good day,

I'm using the @EntityListeners(AuditEntityListener.class) and 
@CreatedOn, @ModifiedOn and @ModifiedBy annotations on an Entity bean 
with the difference that I have a custom implementation of 
java.time.ChronoLocalDateTime which converts any LocalDateTime + 
ZoneOffset OR a ZonedDateTime to be the UTC date & time.

    public class UTCDateTime implements ChronoLocalDateTime<LocalDate>,
    Serializable {

       private static final long serialVersionUID = 6492792765662073566L;
       private static final ZoneOffset UTC = ZoneOffset.UTC;
       private final LocalDateTime datetime;

       // a lot of other details left out

The entity bean parts

    public class InsertableAuditableBean extends BaseBean implements
    InsertableAuditable {

       @Size(min = 1, max = 50)
       @Column(name = "zz_inserted_by", length = 50, nullable = false)
       private String insertedBy;

       @Temporal(value = TemporalType.TIMESTAMP)
       @Column(name = "zz_inserted_on", nullable = false)
       private UTCDateTime insertedOn;

       // getters & setters

    public class UpdateableAuditableBean extends InsertableAuditableBean
    implements UpdateableAuditable {

       @Size(min = 1, max = 50)
       @Column(name = "zz_updated_by", length = 50, nullable = true)
       private String updatedBy;

       @Temporal(value = TemporalType.TIMESTAMP)
       @Column(name = "zz_updated_on", nullable = true)
       private UTCDateTime updatedOn;

       // getters & setters

    @Table(schema = "data", name = "manufacturer", uniqueConstraints = {
         @UniqueConstraint(columnNames = { "man_name", "man_country" })
         @AttributeOverride(name = "primaryKey", column = @Column(name =
         @AttributeOverride(name = "insertedBy", column = @Column(name =
         @AttributeOverride(name = "insertedOn", column = @Column(name =
         @AttributeOverride(name = "updatedBy", column = @Column(name =
         @AttributeOverride(name = "updatedOn", column = @Column(name =
    @SequenceGenerator(name = "default_seq", schema = "data",
    sequenceName = "manufacturer_man_serial_seq",
         allocationSize = 1)
    public class Manufacturer extends MirroredUpdateableAuditableBean
    implements IManufacturer {
       // nothing special here

There is also a custom AttributeConverter for the UTCDateTime class 
because the epoch value is saved in the database.

    @Converter(autoApply = true)
    public class UTCDateTimePersistenceConverter implements
    AttributeConverter<UTCDateTime, Long> {

       public Long convertToDatabaseColumn(final UTCDateTime entityValue) {
         Long res = null;
         if (entityValue != null) {
           res = entityValue.toMillis();
         return res;

       public UTCDateTime convertToEntityAttribute(final Long
    databaseValue) {
         UTCDateTime res = null;
         if (databaseValue != null) {
           res = new UTCDateTime(Instant.ofEpochMilli(databaseValue));
         return res;

Now when I persist the entity I get the following exception (the last 
bit with the real cause):

    Caused by:
    Failed calling Repository:
    Caused by: java.lang.reflect.InvocationTargetException
    Caused by: Failed
    to set property Manufacturer.insertedOn, is this a temporal type?
    Caused by: java.lang.IllegalArgumentException: Annotated field is
    not a date class: class

Is there a way to implement my own and and use 
them to create the instance of UTCDateTime?

Would it be correct to write my own EntityListener --> 
UTCDateTimeAuditListener and use it 
@EntityListeners(UTCDateTimeAuditEntityListener.class) where 
UTCDateTimeAuditListener follows the approach?
Secondly, do I need to use a CDI Qualifier somewhere to make sure that 
my UTCDateTimeAuditEntityListener gets a reference to the correct 
PrePersistAuditListener and PreUpdateAuditListener that knows how to 
construct the UTCDateTime instance?

Lastly, I don't know if it is relevant, but where does fit into this 

Thank you for your time

Kind regards,
Nico Schlebusch <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message