2
我有一個Spring MVC web安裝與Spring ORM/Hibernate持久層。我已將LocalContainerEntityManagerFactoryBean
配置爲自動掃描包中的持久性實體,因此我不需要持久性xml配置。如何配置沒有持久性xml的休眠屬性
如何設置我的bean配置,以便在啓動時顯示生成的查詢並使用模型更改刷新數據庫?
我有一個Spring MVC web安裝與Spring ORM/Hibernate持久層。我已將LocalContainerEntityManagerFactoryBean
配置爲自動掃描包中的持久性實體,因此我不需要持久性xml配置。如何配置沒有持久性xml的休眠屬性
如何設置我的bean配置,以便在啓動時顯示生成的查詢並使用模型更改刷新數據庫?
LocalContainerEntityManagerFactoryBean
延伸AbstractEntityManagerFactoryBean
,其中包含setJpaProperties(Properties)
方法。您可以使用此方法將自定義屬性傳遞給此bean。
Properties properties = new Properties();
properties.put("hibernate.show_sql", "true");
properties.put("hibernate.hbm2ddl.auto", "create-drop");
entityManagerFactoryBean.setJpaProperties(properties);
或者,如果你想這樣做的Spring配置文件:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
...
<property name="jpaProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
</props>
</property>
...
</bean>