Announcement Announcement Module
Collapse
No announcement yet.
Configuring EntityListener without Persistence.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring EntityListener without Persistence.xml

    I've started the migration of my repository from Spring3.0 -> Spring3.1 and one of the areas which is causing some problem is the migration to the new way of handling entityManagers. Right now I am configuring it using a simple standard approach:

    Code:
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		
            <property name="packagesToScan" value="foo.bar" />
            <property name="dataSource" ref="dataSource" />
            
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="generateDdl" value="${db.generateDdl}"/>
    				<property name="databasePlatform" value="${db.dialect}" />
    				<property name="showSql" value="${db.showSql}" />
    			</bean>
    		</property>
    
    		<property name="jpaPropertyMap">
    			<map>
    				<entry key="namingStrategy" value="foo.bar.FooBarNamingStrategy"/>
    			</map>
    		</property>
    	</bean>
    This allows me to configure the Entities without specifying the persistence.xml file. However it is unclear how the orm.xml file is to be treated in this new environment as there are entity listeners configured within it:

    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 http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" version="2.0">
    
        <persistence-unit-metadata>
            <persistence-unit-defaults>
                <entity-listeners>
                    <entity-listener class="org.springframework.data.jpa.domain.support.AuditingEntityListener" />
                </entity-listeners>
            </persistence-unit-defaults>
        </persistence-unit-metadata>
    
    </entity-mappings>
    Without the persistence.xml how does one tell spring that it needs to configure an entity listener on all of the spring beans so that they will support auditing?

  • #2
    I am also looking for this solution for ages now. How did it go? Did you solve it?

    Could you please submit a solution if you solved it?

    Comment


    • #3
      With spring 3.1 a new mappingResource property has been added. That property allow to specify the path of the orm.xml file. (see https://jira.springsource.org/browse/SPR-8440).

      Unfortunately I'm not sure this really work because I cannot get the AuditingEntityListener to work in my project (see http://forum.springsource.org/showth...EntityListener)

      Andrea

      Comment

      Working...
      X