如何在Spring中使用Annotations和纯Java设置hibernate.hbm2ddl.auto [英] How to set hibernate.hbm2ddl.auto in Spring with Annotations and pure Java
问题描述
如何在Spring中仅使用Java和注释来设置以下内容。
< property name =hibernate.hbm2ddl.autovalue =update/>
p>
我应该有可能,并且我确信让项目xml免费更加简洁。
PS:这应该不是很重要,但我在Heroku上运行。
将此添加到dataSource()是的,它解决了我的问题。
final属性hibernateProperties(){
final属性hibernateProperties = new Properties();
hibernateProperties.setProperty(hibernate.hbm2ddl.auto,update);
hibernateProperties.setProperty(hibernate.dialect,org.hibernate.dialect.PostgreSQLDialect);
hibernateProperties.setProperty(hibernate.show_sql,true);
返回hibernateProperties;
}
完整的例子在这里 https://github.com/arose13/Heroku-Spring-Postgres-Example 。
编辑PS :对于这行 hibernateProperties.setProperty(hibernate.hbm2ddl.auto,update);
检出这个 stackoverflow问题找出最好的价值,如果 update
不适合您。
How would one go about setting up the following in Spring using only Java and annotations.
<property name="hibernate.hbm2ddl.auto" value="update"/>
I amIt should be possible and I do believe it is a lot cleaner to make projects xml free.
PS: This shouldn't be important but I'm running this on Heroku.
Added this to the class where the dataSource() is and it fixed my issue.
final Properties hibernateProperties() {
final Properties hibernateProperties = new Properties();
hibernateProperties.setProperty("hibernate.hbm2ddl.auto", "update");
hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
hibernateProperties.setProperty("hibernate.show_sql", "true");
return hibernateProperties;
}
Full example is here https://github.com/arose13/Heroku-Spring-Postgres-Example.
EDIT PS: For this line hibernateProperties.setProperty("hibernate.hbm2ddl.auto","update");
check out this stackoverflow question to figure out the best value if update
isn't right for you.
这篇关于如何在Spring中使用Annotations和纯Java设置hibernate.hbm2ddl.auto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!