我有一个在Websphere Liberty上运行的应用程序,该应用程序应该比较2个数据库/方案中的表。
用户应该能够输入连接数据,例如主机和凭据。
我正在使用Hibernate访问应用程序数据库。
我尝试使用多个持久性单元,一个用于应用程序数据库,一个用于所有其他数据库。
但是我有两个问题:我得到“非法尝试征募多个1PC XAResources”有时会出现错误
可以查询两个数据库用户提交的凭据,但除非连接,否则我没有任何结果到server.xml文件中列出的与DataSource相同的数据库
这是服务器上server.xml上的数据源(dbs是oracle dbs)
这是EJB模块上的persistence.xml<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
jdbc/MyDS
classes...
value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" />
value="org.hibernate.dialect.Oracle9iDialect" />
value="false" />
jdbc/OtherOracle
classes...
value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform" />
value="org.hibernate.dialect.Oracle9iDialect" />
value="false" />
在Java Bean上,我使用EntityManagerFactory@PersistenceUnit(unitName = "other-persistence")
private EntityManagerFactory emf;
并且我使用这样的自定义凭据创建实体管理器Map properties = new HashMap();
properties.put("hibernate.connection.driver_class", "oracle.jdbc.OracleDriver");
properties.put("hibernate.connection.url", myCustomCreatedConnectionUrl);
properties.put("hibernate.connection.username", customUser);
properties.put("hibernate.connection.password", customPassword);
properties.put("hibernate.dialect", "org.hibernate.dialect.Oracle9iDialect");
properties.put("hibernate.show-sql", "true");
EntityManager entityManager = emf.createEntityManager(properties);
如果我使用getProperties检查EntityManager属性,一切似乎都是正确的。但是,仅当凭据/主机为数据源=时查询才有效。否则我没有结果(但没有错误)
问题可能是什么?有没有一种方法可以只使用一个持久性单元,但可以对不同的查询使用自定义的主机/凭据?