Announcement Announcement Module
Collapse
No announcement yet.
Spring Data Auditing: cannot make AuditingEntityListener Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data Auditing: cannot make AuditingEntityListener

    I'm trying to configure the spring data jpa auditing functionality on my project (Hibernate 4.1.6, hibernate-jpa 2.0, spring-data-jpa 1.1.0, spring 3.1.2) but I'm not able to make it work.

    I think the problem is that I'm not able to register the AuditingEntityListener but I'm not sure. I tried to set a breakpoint in all its methods but they never gets called including the afterPropertiesSet.

    Since I don't have a persistence.xml file I tried to use the new mappingResources property of LocalContainerEntityManagerFactoryBean (https://jira.springsource.org/browse/SPR-8440).

    This is from my context.xml:

    Code:
    <jpa:repositories base-package="package.domain" />
    	
    <jpa:auditing auditor-aware-ref="auditorAware" />
    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    	<property name="dataSource" ref="dataSource" />
    	<property name="packagesToScan" value="package.domain.model" />
    	<property name="mappingResources">
    		<value>package/domain/domain-orm.xml"</value>
    	</property>
    
    	<property name="jpaVendorAdapter">
    		<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    			...
    		</bean>
    	</property>
    	<property name="jpaProperties">
    	...
    	</property>
    </bean>
    
    <context:annotation-config />
    This is the contento of the "package/domain/domain-orm.xml" in my classpath:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd" version="2.0">
    	<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>
    </entity-mappings>
    It seems to me that the domain-orm.xml file is completely ignored: i tried to put errors in this file (invalid xml, wrong class name) and nothing happens.

    Any suggestion on what to check is welcome

    Andrea

  • #2
    Solved: it was a small typo in the file name (a traling quote that shouldn't be there).

    Andrea

    Comment

    Working...
    X