Spring 3.1.1 Hibernate 4.1.1 jsf 2.1.6 のデモ プロジェクトがあります。
***タグ内の「<」の開始後の空白は無視してください: ***
persistance.xml ファイルでは、次のような構成を使用しています。
< ?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>
そして、私のapplicationContext.xmlスナップショットは以下の通りです:
< 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>
これで、任意のドメイン クラスを作成するたびに、persistence.xml にエントリを追加する必要があります。すべてのクラスに適切に注釈が付けられます。
ドメイン クラスのスナップショット:
@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;
................
.................
}
新しいドメイン クラスが作成され、persistence.xml タグ エントリが不要になり、SQL テーブルが DB に自動的に作成されるようにするにはどうすればよいですか。
私はすでにapplicationContext.xmlに以下を追加しているので
< prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto} < /prop>
< prop key="hibernate.show_sql">${hibernate.show_sql} < /prop>