猿问

将实体绑定到具有 2 个数据源的特定持久性单元

我有两个持久性单元persistence.xml和两个数据源,standalone.xml但我无法将表 A 绑定到持久性 1,将表 B 绑定到持久性 2


像这样


<persistence-unit name="itsetup-persistence-unit-dev1" transaction-type="JTA">

    <description>Forge Persistence Unit</description>

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <jta-data-source>java:/itsetup-dev1</jta-data-source>

    ...


<persistence-unit name="itsetup-persistence-unit-dev3" transaction-type="JTA">

    <description>Forge Persistence Unit</description>

    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    <jta-data-source>java:/itsetup-dev3</jta-data-source>

    <class>my.package.User</class>

    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    ...


<datasource jndi-name="java:/itsetup-dev3" pool-name="itsetup-dev3" enabled="true" use-java-context="true">

    <connection-url>jdbc:informix-sqli://server:9991/database</connection-url>

    <driver-class>com.informix.jdbc.IfxDriver</driver-class>

    <driver>ifxjdbc.jar</driver>

    <security>

    ...

这是我的用户模型


@Entity

@PersistenceContext(unitName = "itsetup-persistence-unit-dev3")

@Table(name = "user_file")

public class User {

我的用户服务在哪里


@PersistenceContext(unitName = "itsetup-persistence-unit-dev3")

private EntityManager em;

课程表是


@Entity

@PersistenceContext(unitName = "itsetup-persistence-unit-dev1")

@Table(name = "ppp_course")

public class Course {

和我的课程服务


@PersistenceContext(unitName = "itsetup-persistence-unit-dev1")

private EntityManager em;

但是当我运行服务器时,它总是将其他表生成到 dev3 数据库中,就像它没有查看 dev1 数据库一样 Table not found: ppp_course


我怎么能解决这个问题?


倚天杖
浏览 113回答 1
1回答

忽然笑

删除<property name="hibernate.archive.autodetection" value="class" />的<persistence-unit name="itsetup-persistence-unit-dev3" transaction-type="JTA">。但不得不失去自动检测功能。
随时随地看视频慕课网APP

相关分类

Java
我要回答