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>