删除persistence.xml hibernate </class>中<class>标签的用法

时间:2013-05-31 10:45:40

标签: hibernate persistence.xml

我有一个关于Spring 3.1.1 Hibernate 4.1.1 jsf 2.1.6

的演示项目

* 请在“&lt;”开始之后忽略任何白色空白标签:*

在persistance.xml文件中,我使用的配置如下:


  

&LT; ?xml version =“1.0”encoding =“UTF-8”?&gt;
  &LT;持久性xmlns =“http://java.sun.com/xml/ns/persistence”version =“1.0”&gt;

<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 ***-->
  

&LT; /持久性部&gt;

     

&LT; /持久&GT;

我的applicationContext.xml snipeshot如下:


  

&LT; bean id =“entityManagerFactory”class =“org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean”scope =“singleton”&gt;

    <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>

现在,每当我创建任何域类时,我都必须在persistence.xml中添加一个条目 所有课程都有适当的注释。

域类的Snipeshot:

  

* 此处导入*
  @Indexed
  @Entity
  @Table(name =“USER”)
  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  public abstract class User实现Serializable {
      @Id
      @DocumentId
      @Column(name =“ID”,length = 20)
      @Field(index = Index.YES)
      private String id;
          ................
          .................
    }

应该做什么,以便创建任何新的域类,不需要persistence.xml标记条目,并且在DB中自动创建SQL表

因为我已经在applicationContext.xml中添加了以下内容

  

&LT; prop key =“hibernate.hbm2ddl.auto”&gt; $ {hibernate.hbm2ddl.auto}&lt; /丙&GT;

     

&LT; prop key =“hibernate.show_sql”&gt; $ {hibernate.show_sql}&lt; /丙&GT;

1 个答案:

答案 0 :(得分:0)

entityManagerFactory bean声明

中包含以下属性
<property name="packagesToScan" value="com.myapp.domain"/>

从persistence.xml中删除所有类声明