[
https://issues.apache.org/jira/browse/ARIES-1023?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14176256#comment-14176256
]
Giuseppe Gerla commented on ARIES-1023:
---------------------------------------
Dear all
I linked ARIES-1079 to this issue because they are about same problem.
I make 2 commit to fix this issue on the trunk my fork
(1561c1d4b0e240fe0792110e448f3665315c0a49 and
967433b3b77c07b3667a4632261a2883d97bd79d)
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 2 commit
(d0e91720881c814510c4f268c2c51e1386e0e32f and
7734d166c17c9da5bc538078ab6a77175da68aa8) 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)