2013-05-31 68 views
0

我對春天的Hibernate 3.1.1 4.1.1 JSF演示項目2.1.6刪除<class>標籤的使用persistence.xml中冬眠

* 請忽略任何空格的「<」在開始後標記:*

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


< XM升版本= 「1.0」 編碼= 「UTF-8」?>
< 持久的xm​​lns = 「http://java.sun.com/xml/ns/persistence」 版本= 「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 ***--> 

< /持久性單元>

< /持久>

和我的applicationContext.xml中snipeshot下面是:


<豆ID = 「entityManagerFactory的」 類= 「org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean」 範圍= 「單身」>

<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 所有課程均正常annoted。

Snipeshot域類:

* 進口這裏*
@Indexed
@Entity
@Table(name = 「USER」)
@Inheritance(策略= InheritanceType。 TABLE_PER_CLASS)
public abstract class User實現Serializable {
@Id
@DocumentId
@Column(名稱= 「ID」,長度= 20)
@Field(指數= Index.YES)
私人字符串ID;
................
.................
}

應該是什麼這樣就可以創建任何新的域類,不需要persistence.xml標記條目,並且在DB中自動創建SQL表。

因爲我已經在applicationContext中添加了以下內容。XML

<支撐鍵= 「hibernate.hbm2ddl.auto」> $ {hibernate.hbm2ddl.auto} < /丙>

<丙鍵= 「hibernate.show_sql」> $ {hibernate.show_sql } < /丙>

回答

0

納入entityManagerFactory bean聲明以下屬性

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

並從persistence.xml中刪除所有類聲明