You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by lbu <lb...@gmail.com> on 2012/01/17 22:57:20 UTC

Karaf, JPA and ConfigAdmin

Hi all,
I'm new to OSGi and in particular to "OSGi 4 enterprise" and I'm looking for
the best way to configure JPA for different environments/customers/etc
without having to change my JPA bundle.

My first thought was to override the properties in persistence.xml via
ConfiAdmin but I have not found any reference on this topic, should it be
possible ? 

If not is there any other option to achieve what I'm looking for ?

Regards,
Luca
   

--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-JPA-and-ConfigAdmin-tp3667564p3667564.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Karaf, JPA and ConfigAdmin

Posted by lbu <lb...@gmail.com>.
Issue logged here: https://issues.apache.org/jira/browse/ARIES-1023



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-JPA-and-ConfigAdmin-tp3667564p4028564.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Karaf, JPA and ConfigAdmin

Posted by lbu <lb...@gmail.com>.
No I have not work on it any more. 
As today I've exposed the data-source as an OSGi service, I'll test it again
with karaf 3.0 and aries 1.0.

--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-JPA-and-ConfigAdmin-tp3667564p4025192.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Karaf, JPA and ConfigAdmin

Posted by lbu <lb...@gmail.com>.
I've tried the following configuration:

<blueprint
 xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
 xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
 xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">

 <cm:property-placeholder persistent-id="DM-CFG">
   <cm:default-properties>
     <cm:property name="jdbc.url"
value="jdbc:derby:./data/jpa;create=true"/>
   </cm:default-properties>
 </cm:property-placeholder>

 <bean id="DM" class="lb.sandbox.osgi.jpa.DataManager" init-method="init">
   <jpa:context property="em" unitname="LBU" type="EXTENDED">
     <map>
       <entry key="javax.persistence.jdbc.url" value="${jdbc.url}"/>
     </map>
   </jpa:context>
  </bean>

  <service ref="DM" interface="lb.sandbox.osgi.jpa.IDataManager"/>
    
</blueprint>


But I got the following exception even the example has been taken from the
aries webpage :

2012-01-20 15:55:22,471 | ERROR | rint Extender: 1 | BlueprintContainerImpl          
| container.BlueprintContainerImpl  358 | 9 - org.apache.aries.blueprint -
0.3.1 | Unable to start blueprint container for bundle lb.sandbox.osgi.jpa
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to
validate xml
	at
org.apache.aries.blueprint.container.Parser.validate(Parser.java:288)[9:org.apache.aries.blueprint:0.3.1]
	at
org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:275)[9:org.apache.aries.blueprint:0.3.1]
	at
org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:227)[9:org.apache.aries.blueprint:0.3.1]
	at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_29]
	at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_29]
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)[:1.6.0_29]
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)[:1.6.0_29]
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_29]
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_29]
	at java.lang.Thread.run(Thread.java:662)[:1.6.0_29]
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid
content was found starting with element 'map'. One of
'{"http://aries.apache.org/xmlns/jpa/v1.1.0":map}' is expected.
	at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:417)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3182)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1806)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.beginNode(DOMValidatorHelper.java:273)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:240)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:186)[:1.6.0_29]
	at
com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:104)[:1.6.0_29]
	at javax.xml.validation.Validator.validate(Validator.java:127)[:1.6.0_29]
	at
org.apache.aries.blueprint.container.Parser.validate(Parser.java:285)[9:org.apache.aries.blueprint:0.3.1]
	... 10 more


Do you see any misconfiguration in my blueprint ?



--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-JPA-and-ConfigAdmin-tp3667564p3675652.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Karaf, JPA and ConfigAdmin

Posted by Ioannis Canellos <io...@gmail.com>.
I haven't tried it myself. Have you? It would be awsome if you could provide some feedback about it.

On 19 Ιαν 2012, at 1:22 μ.μ., lbu wrote:

> 
> What about a blueprint configuration like the one below? 
> 
> <blueprint 
>  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
>  xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
>  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
> 
>  <cm:property-placeholder persistent-id="my_object_id">
>    <cm:default-properties>
>      <cm:property name="jpa_param_1" value="A"/>
>      <cm:property name="jpa_param_2" value="B"/>
>    </cm:default-properties>
>  </cm:property-placeholder>
> 
>  <bean id="my_object">
>    <jpa:context property="em" unitname="unit_1" type="EXTENDED">
>      <map>
>        <entry key="jpa_param_1" value="${jpa_param_1}" />
>        <entry key="jpa_param_2" value="${jpa_param_1}" />
>      </map>
>    </jpa:context>
>  </bean>
> 
> </blueprint>
> 
> 
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-JPA-and-ConfigAdmin-tp3667564p3672053.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Ioannis Canellos
FuseSource

Blog: http://iocanel.blogspot.com
Apache Karaf Committer & PMC
Apache Camel Committer
Apache ServiceMix  Committer
Apache Gora Committer
Apache DirectMemory Committer


Re: Karaf, JPA and ConfigAdmin

Posted by lbu <lb...@gmail.com>.
What about a blueprint configuration like the one below? 

<blueprint 
  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" 
  xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.1.0"
  xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
  
  <cm:property-placeholder persistent-id="my_object_id">
    <cm:default-properties>
      <cm:property name="jpa_param_1" value="A"/>
      <cm:property name="jpa_param_2" value="B"/>
    </cm:default-properties>
  </cm:property-placeholder>

  <bean id="my_object">
    <jpa:context property="em" unitname="unit_1" type="EXTENDED">
      <map>
        <entry key="jpa_param_1" value="${jpa_param_1}" />
        <entry key="jpa_param_2" value="${jpa_param_1}" />
      </map>
    </jpa:context>
  </bean>
  
</blueprint>


--
View this message in context: http://karaf.922171.n3.nabble.com/Karaf-JPA-and-ConfigAdmin-tp3667564p3672053.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Karaf, JPA and ConfigAdmin

Posted by Ioannis Canellos <io...@gmail.com>.
I am not sure if you can have property place holders (wired with config admin) inside persistence.xml. At least I have not seen such example so far.
If when you switch customers, environments etc, the only thing that changes is the datasource, I think that you can expose the datasource as an osgi service using a managed service and then reuse the datasource in your persitence.xml via jndi (with aries jndi).
This way you can dynamically change your datasource service instead.

On 17 Ιαν 2012, at 11:57 μ.μ., lbu wrote:

> Hi all,
> I'm new to OSGi and in particular to "OSGi 4 enterprise" and I'm looking for
> the best way to configure JPA for different environments/customers/etc
> without having to change my JPA bundle.
> 
> My first thought was to override the properties in persistence.xml via
> ConfiAdmin but I have not found any reference on this topic, should it be
> possible ? 
> 
> If not is there any other option to achieve what I'm looking for ?
> 
> Regards,
> Luca
> 
> 
> --
> View this message in context: http://karaf.922171.n3.nabble.com/Karaf-JPA-and-ConfigAdmin-tp3667564p3667564.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

Ioannis Canellos
FuseSource

Blog: http://iocanel.blogspot.com
Apache Karaf Committer & PMC
Apache Camel Committer
Apache ServiceMix  Committer
Apache Gora Committer
Apache DirectMemory Committer