karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Soto <alex.s...@envieta.com>
Subject Re: Aries JPA: The persistence unit has incomplete configuration and cannot be created.
Date Thu, 24 May 2018 20:02:53 GMT
Thank you François.

The issue is that with Hibernate, you need to configure a Dialect, which is different for
each database.
I want to keep this outside the bundle, so I can configure different databases.
Looks like Aries JPA can do this, but I can’t figure out how it works.

Best regards,
Alex soto




> On May 24, 2018, at 3:56 PM, Francois Papon <francois.papon@openobject.fr> wrote:
> 
> Hi,
> 
> I have a project using JPA and EclipseLink that is working :
> 
> org.ops4j.datasource-myapp.cfg :
> 
> osgi.jdbc.driver.class=org.postgresql.Driver
> dataSourceName=myapp
> databaseName=db_myapp
> serverName=127.0.0.1
> portNumber=5432
> user=xxxx
> password=xxxx
> 
> persistence.xml :
> 
>     <persistence-unit name="my-persistence-unit" transaction-type="JTA">
>         <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
>         <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=myapp)</jta-data-source>
> 
> ...
> 
> This is the only parameters I'm using.
> François
> 
> 
> Le 24/05/2018 à 23:41, Alex Soto a écrit :
>> File:  org.ops4j.datasource-responder.cfg
>> 
>> 
>> osgi.jdbc.driver.name = mariadb
>> dataSourceName=responder
>> url = jdbc:mariadb://localhost:3306/responder?characterEncoding=UTF-8&useServerPrepStmts=true
<mariadb://localhost:3306/responder?characterEncoding=UTF-8&useServerPrepStmts=true>
>> 
>> user=XXXXX
>> password=XXXXX
>> databaseName=responder
>> 
>> ops4j.preHook=responderDB
>> 
>> 
>> This is picked up by PAX-JDBC and registered as a service:  osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)
>> I want the persistence unit  to use this DataSource.
>> 
>> Best regards,
>> Alex soto
>> 
>> 
>> 
>> 
>>> On May 24, 2018, at 3:31 PM, Francois Papon <francois.papon@openobject.fr
<mailto:francois.papon@openobject.fr>> wrote:
>>> 
>>> Hi Alex,
>>> 
>>> Where is configured your JDBC url ? Can you share it ?
>>> 
>>> François
>>> 
>>> Le 24/05/2018 à 23:26, Alex Soto a écrit :
>>>> If I change my persistence.xml to this:
>>>> 
>>>> 
>>>> 	<persistence-unit name="responderPersistenUnit" transaction-type="JTA">
>>>> 		<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)</jta-data-source>
>>>> 		<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)</jta-data-source>
   		
>>>> 	</persistence-unit>
>>>> 
>>>> And the configuration entries to:
>>>> 
>>>> 	<config name="org.apache.aries.jpa.responderPersistenUnit">
>>>>     		javax.persistence.provider=org.hibernate.jpa.HibernatePersistenceProvider
>>>>     		javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
>>>>     		hibernate.dialect=org.hibernate.dialect.MariaDBDialect
>>>>     		hibernate.show_sql=false
>>>>     		hibernate.format_sql=true
>>>>     		hibernate.hbm2ddl.auto=none
>>>> 	</config>
>>>> 
>>>> Then the error Is:
>>>> 
>>>> 
>>>> java.lang.IllegalArgumentException: Cannot rebind to a different database
driver, as per the JPA service specification
>>>> 	at org.apache.aries.jpa.container.impl.AriesEntityManagerFactoryBuilder.processProperties(AriesEntityManagerFactoryBuilder.java:225)
~[?:?]
>>>> 	at org.apache.aries.jpa.container.impl.AriesEntityManagerFactoryBuilder.createEntityManagerFactory(AriesEntityManagerFactoryBuilder.java:173)
~[?:?]
>>>> 	at org.apache.aries.jpa.container.impl.ManagedEMF.updated(ManagedEMF.java:75)
~[?:?]
>>>> 	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)
~[8:org.apache.felix.configadmin:1.8.16]
>>>> 	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)
[8:org.apache.felix.configadmin:1.8.16]
>>>> 	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)
[8:org.apache.felix.configadmin:1.8.16]
>>>> 	at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1479)
[8:org.apache.felix.configadmin:1.8.16]
>>>> 	at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1435)
[8:org.apache.felix.configadmin:1.8.16]
>>>> 	at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141) [8:org.apache.felix.configadmin:1.8.16]
>>>> 	at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109) [8:org.apache.felix.configadmin:1.8.16]
>>>> 	at java.lang.Thread.run(Thread.java:748) [?:?]
>>>> 
>>>> 
>>>> If I remove the line javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver
from the config file above, then I get the previous error about configuration not being completed.
 What I am trying to do is to not  hard code  the hibernate.dialect inside the bundle, so
I can switch to a different database without having to rebuild.
>>>> 
>>>> Also, my DataSource is already created by PAX JDBC Config and this I don’t
want to change, since I am using PreHook facility there to run LiquiBase migrations.
>>>> Any hints or examples appreciated.
>>>> 
>>>> 
>>>> Best regards,
>>>> Alex soto
>>>> 
>>>> 
>>>> 
>>>> 
>>>>> On May 24, 2018, at 1:41 PM, Alex Soto <alex.soto@envieta.com <mailto:alex.soto@envieta.com>>
wrote:
>>>>> 
>>>>> Hello,  
>>>>> 
>>>>> I am using Aries JPA 2.7.0, I am trying provide the JPA persistence configuration
using configuration file.  So my persistence.xml.
>>>>> 
>>>>> <persistence version="2.0"
>>>>> 	xmlns="http://java.sun.com/xml/ns/persistence <http://java.sun.com/xml/ns/persistence>"
>>>>> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance <http://www.w3.org/2001/XMLSchema-instance>"
>>>>> 	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence <http://java.sun.com/xml/ns/persistence>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd <http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd>">
>>>>> 
>>>>> 	<persistence-unit name="responderPersistenUnit" transaction-type="JTA">
>>>>> 		<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
>>>>> 	</persistence-unit>
>>>>> </persistence>
>>>>> 
>>>>> I deploy config file as part of my feature:
>>>>> 
>>>>> <config name="org.apache.aries.jpa.responderPersistenUnit">
>>>>>     hibernate.dialect=org.hibernate.dialect.MariaDBDialect
>>>>>     hibernate.show_sql=false
>>>>>     hibernate.format_sql=true
>>>>>     hibernate.hbm2ddl.auto=none
>>>>>     jta-data-source=osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)
>>>>>     non-jta-data-source=osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)
   		
>>>>> </config>
>>>>> 
>>>>> When I run, the following exception is thrown:
>>>>> 
>>>>> java.lang.IllegalArgumentException: The persistence unit responderPersistenUnit
has incomplete configuration and cannot be created. The configuration is{non-jta-data-source=osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder),
hibernate.format_sql=true, hibernate.hbm2ddl.auto=none, hibernate.dialect=org.hibernate.dialect.MariaDBDialect,
jta-data-source=osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder), felix.fileinstall.filename=file:/Users/asoto/git/encryptedquery/responder/dist/target/encryptedquery-responder-dist-1.0.0-SNAPSHOT/etc/org.apache.aries.jpa.responderPersistenUnit.cfg
<file:///Users/asoto/git/encryptedquery/responder/dist/target/encryptedquery-responder-dist-1.0.0-SNAPSHOT/etc/org.apache.aries.jpa.responderPersistenUnit.cfg>,
hibernate.show_sql=false, javax.persistence.spi.PersistenceUnitTransactionType=JTA, service.pid=org.apache.aries.jpa.responderPersistenUnit}
>>>>> 	at org.apache.aries.jpa.container.impl.AriesEntityManagerFactoryBuilder.createAndPublishEMF(AriesEntityManagerFactoryBuilder.java:365)
~[?:?]
>>>>> 	at org.apache.aries.jpa.container.impl.AriesEntityManagerFactoryBuilder.createEntityManagerFactory(AriesEntityManagerFactoryBuilder.java:183)
~[?:?]
>>>>> 	at org.apache.aries.jpa.container.impl.ManagedEMF.updated(ManagedEMF.java:75)
~[?:?]
>>>>> 	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)
~[8:org.apache.felix.configadmin:1.8.16]
>>>>> 	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)
[8:org.apache.felix.configadmin:1.8.16]
>>>>> 	at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)
[8:org.apache.felix.configadmin:1.8.16]
>>>>> 	at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1479)
[8:org.apache.felix.configadmin:1.8.16]
>>>>> 	at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1435)
[8:org.apache.felix.configadmin:1.8.16]
>>>>> 	at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141)
[8:org.apache.felix.configadmin:1.8.16]
>>>>> 	at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109)
[8:org.apache.felix.configadmin:1.8.16]
>>>>> 	at java.lang.Thread.run(Thread.java:748) [?:?]
>>>>> 
>>>>> 
>>>>> 
>>>>> So Aries JPA is finding the configuration properties I am providing,
but still missing something.  What else is needed as configuration properties? Why is it not
complete the persistent unit?
>>>>> 
>>>>> 
>>>>> Best regards,
>>>>> Alex soto
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>> 
>>> 
>> 
> 


Mime
View raw message