Quantcast

Aries JPA 2.3.0: mapping file not used

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Aries JPA 2.3.0: mapping file not used

jochenw
Hello,

I have just switched from Aries JPA 1.0.4 to 2.3.0, used in combination with EclipseLink 2.6.1. With a H2 database, it works smoothly, and much better than with 1.0.4.

However, I also have a PostgreSQL database where I have organized tables in several schemas. Typically I use a common datasource for the different persistence bundles, and each persistence bundle has a mapping file orm.xml to cope with the according schema:

<?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>schema_one</schema>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
</entity-mappings>

In the persistence.xml, the mapping file is referenced with <mapping-file>META-INF/orm.xml</mapping-file>

That mapping file seems not to work any longer. I receive some "relation xyz does not exist" exception, and when switching on fine logging for EclipseLink, it becomes obvious that the schema name is not used for accessing the tables (just SELECT .... FROM MyTable instead of SELECT .... FROM schema_one.MyTable) .

Of course I could use something like url=jdbc:postgresql://localhost:5432/mydb?currentSchema=schema_one when defining the data source - but this way I would need one data source per persistence bundle.

Is there something special I need to do to re-activate the orm.xml file?

Regards,
Jochen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

jochenw
Sorry, forgot to mention that this happens with Karaf 4.0.4 and 4.0.5, and it is still the case when explicitly installing the JPA 2.4.0 features.

Regards,

Jochen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

Timothyjward
There was a major rewrite of Aries JPA between version 1.x and 2.x. It appears as though the mapping file support was lost (I can find no reference to mapping files in the parser).

This is obviously something that needs to be fixed - is there any way that you can supply a simplified version of this as a test case?

Regards,

Tim

> On 12 Aug 2016, at 10:14, jochenw <[hidden email]> wrote:
>
> Sorry, forgot to mention that this happens with Karaf 4.0.4 and 4.0.5, and it
> is still the case when explicitly installing the JPA 2.4.0 features.
>
> Regards,
>
> Jochen
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Aries-JPA-2-3-0-mapping-file-not-used-tp4047501p4047507.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

jochenw
Hi Timothy,

using the tasklist-blueprint-cdi example (https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-blueprint-cdi), I have exchanged H2 by PostgreSQL, added an orm.xml, exchanged the datasource configuration with one for a PostgreSQL DB, created a PostgreSQL DB named tasklist and a schema named tasklist_schema. And it works.

Then I changed the name of the mapping file from orm.xml to tasklist_orm.xml, and it started writing the tables to the public schema.

So the problem seems to be that with other mapping file names than orm.xml, it doesnt work. My changes are attached below.

Regards,

Jochen

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   
    <persistence-unit name="tasklist" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
       
       
        <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</jta-data-source>
       
       
        <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</non-jta-data-source>
                <mapping-file>META-INF/orm.xml</mapping-file>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>

</persistence>



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>tasklist_schema</schema>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
</entity-mappings>



org.ops4j.datasource-tasklist.cfg:

dataSourceName=tasklist
osgi.jdbc.driver.name = PostgreSQL JDBC Driver-pool-xa
serverName = localhost
portNumber = 5432
databaseName = tasklist
user = postgres
password = postgres



last but not least, a change in the features.xml: replace "pax-jdbc-h2" by "pax-jdbc-postgresql"

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

Timothy Ward
Hi Jochen,

This will probably be occurring because the Persistence Provider is auto-detecting the resource when it is called META-INF/orm.xml. This should be overridable in the persistence.xml, but isn’t.

Regards,

Tim


> On 17 Aug 2016, at 15:06, jochenw <[hidden email]> wrote:
>
> Hi Timothy,
>
> using the tasklist-blueprint-cdi example
> (https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-blueprint-cdi),
> I have exchanged H2 by PostgreSQL, added an orm.xml, exchanged the
> datasource configuration with one for a PostgreSQL DB, created a PostgreSQL
> DB named tasklist and a schema named tasklist_schema. And it works.
>
> Then I changed the name of the mapping file from orm.xml to
> tasklist_orm.xml, and it started writing the tables to the public schema.
>
> So the problem seems to be that with other mapping file names than orm.xml,
> it doesnt work. My changes are attached below.
>
> Regards,
>
> Jochen
>
> persistence.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
>
>    <persistence-unit name="tasklist" transaction-type="JTA">
>        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
>
>
>
> <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</jta-data-source>
>
>
>
> <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</non-jta-data-source>
> <mapping-file>META-INF/orm.xml</mapping-file>
>        <properties>
>            <property name="hibernate.dialect"
> value="org.hibernate.dialect.PostgreSQLDialect"/>
>            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
>        </properties>
>    </persistence-unit>
>
> </persistence>
>
>
>
> 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>tasklist_schema</schema>
>        </persistence-unit-defaults>
>    </persistence-unit-metadata>
> </entity-mappings>
>
>
>
> org.ops4j.datasource-tasklist.cfg:
>
> dataSourceName=tasklist
> osgi.jdbc.driver.name = PostgreSQL JDBC Driver-pool-xa
> serverName = localhost
> portNumber = 5432
> databaseName = tasklist
> user = postgres
> password = postgres
>
>
>
> last but not least, a change in the features.xml: replace "pax-jdbc-h2" by
> "pax-jdbc-postgresql"
>
>
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Aries-JPA-2-3-0-mapping-file-not-used-tp4047501p4047569.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

cschneider
In reply to this post by jochenw
Hmmm .. interesting. We do not have code in Aries JPA that specifically handles mapping files (as far as I know).
So I wonder if this maybe is an issue in hibernate.

Christian

2016-08-17 16:06 GMT+02:00 jochenw <[hidden email]>:
Hi Timothy,

using the tasklist-blueprint-cdi example
(https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-blueprint-cdi),
I have exchanged H2 by PostgreSQL, added an orm.xml, exchanged the
datasource configuration with one for a PostgreSQL DB, created a PostgreSQL
DB named tasklist and a schema named tasklist_schema. And it works.

Then I changed the name of the mapping file from orm.xml to
tasklist_orm.xml, and it started writing the tables to the public schema.

So the problem seems to be that with other mapping file names than orm.xml,
it doesnt work. My changes are attached below.

Regards,

Jochen

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="tasklist" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>



<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</jta-data-source>



<non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</non-jta-data-source>
                <mapping-file>META-INF/orm.xml</mapping-file>
        <properties>
            <property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>

</persistence>



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>tasklist_schema</schema>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
</entity-mappings>



org.ops4j.datasource-tasklist.cfg:

dataSourceName=tasklist
osgi.jdbc.driver.name = PostgreSQL JDBC Driver-pool-xa
serverName = localhost
portNumber = 5432
databaseName = tasklist
user = postgres
password = postgres



last but not least, a change in the features.xml: replace "pax-jdbc-h2" by
"pax-jdbc-postgresql"





--
View this message in context: http://karaf.922171.n3.nabble.com/Aries-JPA-2-3-0-mapping-file-not-used-tp4047501p4047569.html
Sent from the Karaf - User mailing list archive at Nabble.com.



--
--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

Timothy Ward
The issue appears to be that Aries JPA has no code to handle the mapping files element of the persistence unit. As a result no mapping file names are passed to the JPA provider.

I think this is an Aries issue.

Tim

Sent from my iPhone

On 17 Aug 2016, at 21:09, Christian Schneider <[hidden email]> wrote:

Hmmm .. interesting. We do not have code in Aries JPA that specifically handles mapping files (as far as I know).
So I wonder if this maybe is an issue in hibernate.

Christian

2016-08-17 16:06 GMT+02:00 jochenw <[hidden email]>:
Hi Timothy,

using the tasklist-blueprint-cdi example
(https://github.com/cschneider/Karaf-Tutorial/tree/master/tasklist-blueprint-cdi),
I have exchanged H2 by PostgreSQL, added an orm.xml, exchanged the
datasource configuration with one for a PostgreSQL DB, created a PostgreSQL
DB named tasklist and a schema named tasklist_schema. And it works.

Then I changed the name of the mapping file from orm.xml to
tasklist_orm.xml, and it started writing the tables to the public schema.

So the problem seems to be that with other mapping file names than orm.xml,
it doesnt work. My changes are attached below.

Regards,

Jochen

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="tasklist" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>



<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</jta-data-source>



<non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=tasklist)</non-jta-data-source>
                <mapping-file>META-INF/orm.xml</mapping-file>
        <properties>
            <property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>

</persistence>



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>tasklist_schema</schema>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
</entity-mappings>



org.ops4j.datasource-tasklist.cfg:

dataSourceName=tasklist
osgi.jdbc.driver.name = PostgreSQL JDBC Driver-pool-xa
serverName = localhost
portNumber = 5432
databaseName = tasklist
user = postgres
password = postgres



last but not least, a change in the features.xml: replace "pax-jdbc-h2" by
"pax-jdbc-postgresql"





--
View this message in context: http://karaf.922171.n3.nabble.com/Aries-JPA-2-3-0-mapping-file-not-used-tp4047501p4047569.html
Sent from the Karaf - User mailing list archive at Nabble.com.



--
--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

jochenw
The behavior is the same with Eclipselink (I just haven't adapted the tasklist example to Eclipselink - which I use in my application). Might the ORMs look for the default file orm.xml, and only need some configuration input when the filename is different, which Aries JPA does not handle?

Regards,

Jochen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

Timothy Ward
That is exactly my point:


Aries JPA makes no attempt to process the mapping file element(s) in the persistence xml file, so no information will be passed to the provider.

Regards,

Tim

On 18 Aug 2016, at 09:19, jochenw <[hidden email]> wrote:

The behavior is the same with Eclipselink (I just haven't adapted the
tasklist example to Eclipselink - which I use in my application). Might the
ORMs look for the default file orm.xml, and only need some configuration
input when the filename is different, which Aries JPA does not handle?

Regards,

Jochen



--
View this message in context: http://karaf.922171.n3.nabble.com/Aries-JPA-2-3-0-mapping-file-not-used-tp4047501p4047578.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

cschneider
You are right. I just checked in the 1.x jpa code for that. Here is how it is done there:

Christian


2016-08-18 11:40 GMT+02:00 Timothy Ward <[hidden email]>:
That is exactly my point:


Aries JPA makes no attempt to process the mapping file element(s) in the persistence xml file, so no information will be passed to the provider.

Regards,

Tim

On 18 Aug 2016, at 09:19, jochenw <[hidden email]> wrote:

The behavior is the same with Eclipselink (I just haven't adapted the
tasklist example to Eclipselink - which I use in my application). Might the
ORMs look for the default file orm.xml, and only need some configuration
input when the filename is different, which Aries JPA does not handle?

Regards,

Jochen



--
View this message in context: http://karaf.922171.n3.nabble.com/Aries-JPA-2-3-0-mapping-file-not-used-tp4047501p4047578.html
Sent from the Karaf - User mailing list archive at Nabble.com.




--
--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

hraf
This post has NOT been accepted by the mailing list yet.
Hello cschneider

So has the issue been resolved in newer versions ?

thank you
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Aries JPA 2.3.0: mapping file not used

Alex
I had the same issue too.

I have reported it on JIRA Apache Aries: ARIES-1711

I hope this fix will be released as soo as possible. I added in the comments the solution for a fix.
Loading...