我有一个正常项目的多个依赖项,并且每个都有自己的persistence.xml,数据源通过以下配置提供给依赖项目...
<bean id="PUM" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"> <property name="persistenceXmlLocations"><!-- default --> <list>
<value>classpath*:META-INF/persistence.xml</value> </list> </property> <property name="defaultDataSource" ref="DS" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" init-method="method1"/>
我的问题是,如果我正在使用hibernate,我是否可以在依赖项目中的persistance.xml中提及方言...以防使用hibernate ......
答案 0 :(得分:0)
您需要使用EntityManagerFactory手动创建EntityManager。通过这种方式,您可以传递其他属性,这些属性将添加或覆盖persistence.xml文件中设置的属性。由于hibernate dialect是一个普通的属性,你可以用以下方式覆盖它:
EntityManagerFactory emf = // retrieve from spring configuration
Map<String,String> jpaProperties = new HashMap<>();
jpaProperties.put("hibernate.dialect",
"Your desired dialect as would be written in persistence.xml");
EntityManager em = emf.createEntityManager(jpaProperties);