很抱歉提出已在此处理的问题,但我不明白建议的解决方案。至少,不能使它工作: - (
我有3个模式,其中有完全相同的表用于保存来自MDB的消息。我必须根据消息内容选择架构。
我尝试过这里提出的解决方案:
JPA - EclipseLink - How to configure Database Schema name at runtime
或
Modify JPA schema at runtime with EclipseLink running on JBoss
设置orm.xml文件并声明多个持久性单元。当我测试我的代码时,我得到了这个错误,我无法找到解决方案:
我的persistence.xml包含此持久性单元:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="mb-STIRCO" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>minfin.esb.soaesb.dataSource</jta-data-source>
<mapping-file>META-INF/stirCoIn-orm.xml</mapping-file>
<validation-mode>NONE</validation-mode>
<properties>
<property name="eclipselink.target-database" value="DB2"/>
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.logging.logger" value="ServerLogger"/>
<property name="eclipselink.logging.level" value="OFF"/>
<property name="eclipselink.logging.level.sql" value="OFF"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
指向stirCoIn-orm.xml。
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0">
<persistence-unit-metadata>
<persistence-unit-defaults>
<schema>ESB_MB_STIRCO</schema>
</persistence-unit-defaults>
</persistence-unit-metadata>
</entity-mappings>
在运行时,我尝试实例化该持久性单元:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("mb-STIRCO");
EntityManager em2 = emf.createEntityManager();
MessageStirCo myEntity = new MessageStirCo(tsCreateDate, sBody);
em2.persist(myEntity);
当我运行时,我收到此错误:
java.lang.IllegalArgumentException:Object:[id = 0]不是已知的实体类型。
知道我做错了吗?
提前致谢。
劳伦