我有2个DataSource连接,我指定每个连接应该使用哪个类,但我仍然有一些例外:
这是我的applicationContext.xml
<context:component-scan base-package="com.example.video"/>
<context:annotation-config/>
<tx:annotation-driven />
<jee:jndi-lookup id="VOD" jndi-name="java:comp/env/jdbc/VOD" />
<jee:jndi-lookup id="SB" jndi-name="java:comp/env/jdbc/SB" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="VOD" />
<property name="packagesToScan" value="com.example.video" />
<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="entityManagerFactorySB"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="SB" />
<property name="packagesToScan" value="com.example.service" />
<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
</bean>
<bean id="transactionManagerSB"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactorySB"/>
</bean>
<jpa:repositories base-package="com.example.video"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<jpa:repositories base-package="com.example.service"
entity-manager-factory-ref="entityManagerFactorySB"
transaction-manager-ref="transactionManagerSB"/>
这是我的persistence.xml
<persistence-unit name="VOD" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.example.video.model.Product</class>
.
.
<class>com.example.video.model.Task</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
<persistence-unit name="SB" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.example.service.model.ChargingInfo</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>
这是例外: 引起:org.hibernate.HibernateException:缺少表:CHARGINGINFO
答案 0 :(得分:0)
您是否检查过MergingPersistenceUnitManager http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.misc.merging-persistence-units 允许您将多个持久性提供程序组合为一个。
答案 1 :(得分:0)
发现问题,只需从applicationContext.xml
中删除该行&LT; prop key =&#34; hibernate.hbm2ddl.auto&#34;&gt;验证
从bean声明然后它工作正常。