且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Spring JPA Web应用程序中设置一些Hibernate属性?

更新时间:2022-06-22 02:16:40

Spring提供了一种使用AbstractJpaVendorAdapter(setDatabase()setGenerateDdl(),但setGenerateDdl()并不这样)以与提供者无关的方式配置这些选项的方法.采取DDL模式).

Spring provides a way to configure these options in provider-independent way using AbstractJpaVendorAdapter (setDatabase() and setGenerateDdl(), though setGenerateDdl() doesn't take DDL mode).

或者,您可以使用setJpaProperties()(或setJpaPropertyMap())将任意属性传递给LocalContainerEntityManagerFactory:

Alternatively, you can pass arbitrary properties to LocalContainerEntityManagerFactory using setJpaProperties() (or setJpaPropertyMap()):

Properties props = new Properties();
props.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
props.put("hibernate.hbm2ddl.auto", "create");
factoryBean.setJpaProperties(props);