1

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

Abhishek
  • 2,925
  • 4
  • 34
  • 59
  • suppose you try with annotations like this `@PersistenceContext(unitName = "mb-STIRCO") protected EntityManager em; ` this [example](http://www.eclipse.org/eclipselink/documentation/2.5/solutions/testingjpa002.htm) may be helpful. – Rajith Pemabandu Jun 05 '17 at 04:58
  • Nope, I didn't whant to use annotation as the bussinnes will request to change the schemas depending of the contaent of the jms message. So I would have to declare 3 entitymanager if I weel understood. I'll try that. – Laurent Jadoul Jun 05 '17 at 05:08
  • @RajithPemabandu, it works with anotation. Thanks. It's not as dynamic as I wanted but it will do the tricks vor V1. I still 'd like to use the EntityManagerFactory., so I'm keeping searching. If anyone as an idea :-) – Laurent Jadoul Jun 05 '17 at 08:00
  • ok. Good for you. – Rajith Pemabandu Jun 05 '17 at 08:10

0 Answers0