Announcement Announcement Module
Collapse
No announcement yet.
How to define custom AuditingEntityListener in Spring Data JPA? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to define custom AuditingEntityListener in Spring Data JPA?

    The Spring Data JPA docs nicely describe how to enable auditing. I have used this default config successfully without issue.

    Now I have a need to use a custom AuditingEntityListener class instead of the one provided by Spring Data. I am using 1.2.0.RELEASE.

    The problem I'm experiencing is my AuditorAwareBean is not getting injected into my custom AuditingEntityListener (which is almost an exact copy of the Spring Data version.)

    To prevent the instantiation of the Spring Data AuditingEntityListener , I commented out the auditing namespace element in my configuration:

    Code:
    <!-- <jpa:auditing auditor-aware-ref="auditorAware" /> -->
    <bean id="auditorAware" class="com.mycompany.auditing.AuditorAwareImpl" />
    I also modified my orm.xml to use my custom implementation of AuditingEntityListener

    Code:
    <persistence-unit-metadata>
         <persistence-unit-defaults>
            <entity-listeners>
                <entity-listener class="com.mycompany.auditing.AuditingEntityListener" />
            </entity-listeners>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
    Now that I've commented out the auditing namespace element, how do I get my AuditorAwareImpl injected into my custom AuditingEntityListener?

    I can confirm my custom AuditingEntityListener class is getting called. However, the "auditorAware" is always null.

    Disclosure: I also posted this question to Stack Overflow yesterday but since it has not garnered any responses yet I figured I would also post it here. I will update either post (here or SO) if I receive relevant any info. Many thanks!
Working...
X