0

I have a demo project on Spring 3.1.1 Hibernate 4.1.1 jsf 2.1.6

***PLEASE IGNORE ANY WHITESPACES AFTER THE START OF "<" IN A TAG : ***

In the persistance.xml file, I am using the Configuration like the following :


< ?xml version="1.0" encoding="UTF-8"?>
< persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

    <persistence-unit name="app-persistance"
        transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <!-- ********* HAS Entries ********* -->
                <class>com.myapp.domain.classA</class>
                <class>com.myapp.domain.classB</class>
                <!-- ******More Domain classes here ***-->
< /persistence-unit>

< /persistence>

And My applicationContext.xml snapshot is below :


< bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" scope="singleton">
        
        <property name="persistenceUnitName" value="app-persistance" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="javax.persistence.validation.mode">none</prop>
                <prop key="javax.persistence.sharedCache.mode">all</prop>
                <prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.impl.FSDirectoryProvider
                </prop>
                <prop key="hibernate.search.default.indexBase">c:/lucene/indexes</prop>
            </props>
        </property>
        
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
        scope="singleton">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

Now, every time I create a any Domain Class, I have to put an entry into persistence.xml All classes are properly annotated.

Snapshot of a domain class :

@Indexed
@Entity
@Table(name = "USER")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class User implements Serializable {
    @Id
    @DocumentId
    @Column(name = "ID", length = 20)
    @Field(index = Index.YES)
    private String id;
        ................
        .................
  }

What should be done so that any new domain classes created, persistence.xml tag entry wouldn't be required and SQL table gets automatically created in DB

since I have already added the following in applicationContext.xml

< prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto} < /prop>

< prop key="hibernate.show_sql">${hibernate.show_sql} < /prop>
eglease
  • 2,445
  • 11
  • 18
  • 28
Imdad Areeph
  • 91
  • 1
  • 8

1 Answers1

0

Include the following property in entityManagerFactory bean declaration

<property name="packagesToScan" value="com.myapp.domain"/>

And remove all the class declarations from persistence.xml

Rachit Agrawal
  • 685
  • 4
  • 13
  • 35