Sorry to ask a question that has been treated here but I don't understand the proposed solution. At least, can't make it work :-(
I have 3 schema with exactly the same tables used to persists messages from MDBs. I have to choose the schema based on messages content.
I've tried the solution proposed here :
JPA - EclipseLink - How to configure Database Schema name at runtime
or
Modify JPA schema at runtime with EclipseLink running on JBoss
Setting up an orm.xml file and declare several persistence unit. When I tests my code I get this error from which I wasn't able to find the solution :
My persistence.xml contain this persistence unit :
<?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>
Which point to that 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>
At run-time I try to instantiate that persistence unit :
EntityManagerFactory emf = Persistence.createEntityManagerFactory("mb-STIRCO");
EntityManager em2 = emf.createEntityManager();
MessageStirCo myEntity = new MessageStirCo(tsCreateDate, sBody);
em2.persist(myEntity);
When I run this, I get this error :
java.lang.IllegalArgumentException: Object: [ id=0 ] is not a known entity type.
Any idea what I've done wrong?
Thanks in advance.
Laurent