[
https://issues.apache.org/jira/browse/ARIES-1023?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14176256#comment-14176256
]
Giuseppe Gerla edited comment on ARIES-1023 at 12/27/14 3:32 PM:
-----------------------------------------------------------------
Dear all
I linked ARIES-1079 to this issue because they are about same problem.
I make a commit to fix this issue on the trunk of my fork
(35b4a04f5d3ae192013b5e48c4605af221316746)
https://github.com/ggerla/aries.git
After this, I add a test for this functionality. In a persistence file I add a
persistence-unit with only unit name and class list. In a blueprint file I add
injection of the unit with custom properties (database url and driver). I was
surprised because it didn't work.
I make a debug analisys and discover that: Jpa container analize all
persistence file of active bundle and create an EntityManagerFactory for each
unit. The property to create this EMF is only one
(org.apache.aries.jpa.use.data.source.factory).
Then when an EntityManager is required the container create it using the custom
properties setted in blueprint file for that unit.
The problem is that when these properties are passed to EM creation, the JPA
implementation try to create the EM and then to set new properties on it. So if
you want pass the jdbc driver in blueprint file or some other properties used
to create the EM, you cannot!
To improve this behaviour I make a commit
(6c1e08bc31c8e391ed003a9053b814a3fc034988) in wich I add the test and change
the EntityManagerFactory proxy allocation.
Now it works, but I change a lot of "philosophy". So please check my code and
in case merge with Aries trunk.
was (Author: ggerla):
Dear all
I linked ARIES-1079 to this issue because they are about same problem.
I make a commit to fix this issue on the trunk of my fork
(56bf3dffd15be41e1e7151993d495c4ef19a87c1)
https://github.com/ggerla/aries.git
After this, I add a test for this functionality. In a persistence file I add a
persistence-unit with only unit name and class list. In a blueprint file I add
injection of the unit with custom properties (database url and driver). I was
surprised because it didn't work.
I make a debug analisys and discover that: Jpa container analize all
persistence file of active bundle and create an EntityManagerFactory for each
unit. The property to create this EMF is only one
(org.apache.aries.jpa.use.data.source.factory).
Then when an EntityManager is required the container create it using the custom
properties setted in blueprint file for that unit.
The problem is that when these properties are passed to EM creation, the JPA
implementation try to create the EM and then to set new properties on it. So if
you want pass the jdbc driver in blueprint file or some other properties used
to create the EM, you cannot!
To improve this behaviour I make a commit
(80bcaca80a09dd088ba25151376b68b646cffb0e) in wich I add the test and change
the EntityManagerFactory proxy allocation.
Now it works, but I change a lot of "philosophy". So please check my code and
in case merge with Aries trunk.
> Construct a persistence unit with parameters
> --------------------------------------------
>
> Key: ARIES-1023
> URL: https://issues.apache.org/jira/browse/ARIES-1023
> Project: Aries
> Issue Type: Bug
> Components: JPA
> Reporter: Luca Burgazzoli
>
> According to http://aries.apache.org/modules/jpaproject.html it should be
> possible to construct a persistence unit with properties supplied in the OSGi
> blueprint.xml instead of hard-coding them in the persistence.xml but it does
> not seem to work:
> The bean definition:
> <bean id="con_managed_data_service"
> class="lb.examples.karaf.jpa.openjpa.data.ContainerManagedDataService">
> <jpa:context unitname="OPENJPA_PU_JTA" property="entityManager">
> <map>
> <property name="openjpa.Log" value="DefaultLevel=TRACE"/>
> </map>
> </jpa:context>
> <tx:transaction method="*" value="Required"/>
> </bean>
> And the error:
> 2013-03-07 08:30:57,884 | ERROR | BlueprintContainerImpl |
> blueprint.container.BlueprintContainerImpl | org.apache.aries.blueprint.core
> | Unable to start blueprint container for bundle jpa-openjpa
> org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to
> validate xml
> at
> org.apache.aries.blueprint.parser.Parser.validate(Parser.java:288)[7:org.apache.aries.blueprint.core:1.0.1]
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:304)[7:org.apache.aries.blueprint.core:1.0.1]
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:252)[7:org.apache.aries.blueprint.core:1.0.1]
> at
> org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)[7:org.apache.aries.blueprint.core:1.0.1]
> at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_17]
> at
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1.7.0_17]
> at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_17]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)[:1.7.0_17]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)[:1.7.0_17]
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_17]
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_17]
> at java.lang.Thread.run(Thread.java:722)[:1.7.0_17]
> 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:198)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:453)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3232)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1791)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:741)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.beginNode(DOMValidatorHelper.java:277)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:244)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:190)[:1.7.0_17]
> at
> com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:109)[:1.7.0_17]
> at javax.xml.validation.Validator.validate(Unknown Source)[:2.1.0]
> at
> org.apache.aries.blueprint.parser.Parser.validate(Parser.java:285)[7:org.apache.aries.blueprint.core:1.0.1]
> ... 11 more
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)