Hibernate 使用common PesInstance manager处理具有persistence.xml的多个依赖项项目

Hibernate 使用common PesInstance manager处理具有persistence.xml的多个依赖项项目,hibernate,jpa,Hibernate,Jpa,我和一个正常项目一样有多个依赖项,每个依赖项都有自己的persistence.xml,数据源通过以下配置提供给依赖项目 <bean id="PUM" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"> <property name="persistenceXmlLocations"><!-- default -->

我和一个正常项目一样有多个依赖项,每个依赖项都有自己的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,我是否可以在依赖项项目中超越persistence.xml中提到的方言…如果使用hibernate…

您需要使用手动创建EntityManager。通过这种方式,您可以传递其他属性,这些属性将添加或覆盖persistence.xml文件中设置的属性。由于hibernate方言是一个普通属性,您可以通过以下方式覆盖它:

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);