0
votes

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 snipeshot 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, Everytime I Create a any Domain Class, I have to put an entry into persistence.xml All classes are properly annoted.

Snipeshot of a domain class :

*imports here *
@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 would'nt 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>

1

1 Answers

0
votes

Include the following property in entityManagerFactory bean declaration

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

And remove all the class declarations from persistence.xml