1

Below is the error from the log that i see after starting the service... can you help resolving this issue.

2013-08-22 10:35:37,111 | DEBUG | l Console Thread | AbstractServiceReferenceRecipe   | r.AbstractServiceReferenceRecipe  143 | 7 - org.apache.aries.blueprint.core - 1.1.0 | Found initial references null for OSGi service (&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=tenant))(objectClass=javax.persistence.EntityManagerFactory))

2013-08-22 10:35:37,111 | DEBUG | l Console Thread | BlueprintContainerImpl           | container.BlueprintContainerImpl  280 | 7 - org.apache.aries.blueprint.core - 1.1.0 | Running blueprint container for bundle com.igt.arcus.framework.jta.arcus-framework-feature-service in state WaitForInitialReferences
2013-08-22 10:35:37,111 | INFO  | l Console Thread | BlueprintContainerImpl           | container.BlueprintContainerImpl  344 | 7 - org.apache.aries.blueprint.core - 1.1.0 | Bundle com.igt.arcus.framework.jta.arcus-framework-feature-service is waiting for dependencies [(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=tenant))(objectClass=javax.persistence.EntityManagerFactory))]
2013-08-22 10:35:37,112 | DEBUG | l Console Thread | BlueprintEventDispatcher         | ntainer.BlueprintEventDispatcher  136 | 7 - org.apache.aries.blueprint.core - 1.1.0 | Sending blueprint container event BlueprintEvent[type=GRACE_PERIOD, dependencies=[(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=tenant))(objectClass=javax.persistence.EntityManagerFactory))]] for bundle com.igt.arcus.framework.jta.arcus-framework-feature-service
legrandviking
  • 2,348
  • 1
  • 22
  • 29

2 Answers2

2

In case you use Aries JPA you should see two EntityManagerFactory services:

  • jpa-container picks up your bundle with the persistence.xml and creates an Entity manager factory
  • jpa-container-context picks up every EntityManagerFactory service and makes a new managed EntityManagerFactory service with the (org.apache.aries.jpa.proxy.factory=true) service property key-value pair

The second does not exist in your environment. There can be two causes:

  • aries-jpa-container-context is not in your OSGi environment or it is not in ACTIVE state
  • The original EntityManagerFactory service is not registered as some dependency is missing

You can check it if you open an OSGi console and check what services available. If there is no EntityManagerFactory service at all, the second is your problem.

Check if all of your bundles are active! If they are, check if you have all the services that jpa-container needs: TransactionManager, DataSource or DataSourceFactory and a javax.persistence.spi.PersistenceProvider service for Hibernate. If any of the services are missing aries-jpa-container will pick up your bundle but will never create the EntityManagerFactory.

I implemented an own jpa-container that works almost the same way as aries-jpa-container. If you replace the aries-jpa-container (only that one, the jpa-container-context should be left there) it will log more messages at INFO level for you what is missing. The container is available here. A sample application is available that uses hibernate is available at https://github.com/everit-org/osgi-hibernate. After running "mvn install" you will find itests/core/target/eosgi-itests-dist/equinox a subfolder where you can start the working application with on equinox server with bin/runconsole.sh.

Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
  • thank you for your reply..i have checked the jpa-container-context its active ..also i have bundle ..Hibernate-EntityManager active... Comming to the avax.persistence.spi.PersistenceProvider ...i have installed this bundle which exposes & being consumed by hibernate ..Apache Geronimo JSR-317 JPA 2.0 Spec APIorg.apache.geronimo.specs.geronimo-jpa_2.0_spec;singleton=true .. – user2708384 Aug 22 '13 at 19:05
  • Sorry I cannot understand fully your comment. So you have an OSGi service with javax.persistence.spi.PersistenceProvider? – Balazs Zsoldos Aug 22 '13 at 19:17
  • yes i have this bundle which provides me with the required dependency mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1 ..for javax,persistence.spi – user2708384 Aug 22 '13 at 19:25
  • that jar contains the API classes of JPA. It does not register an OSGi service with interface javax.persistence.spi.PersistenceProvider at all. You must install a bundle that instantiates the Hibernate implementation of that interface and registers it as an OSGi service. Now the question again if you have an OSGi service with that interface. Check it in OSGi console! – Balazs Zsoldos Aug 22 '13 at 19:54
  • Have this mvn:org.hibernate/hibernate-osgi/4.2.2.Final..which registers it as service Service ID 259 Types: javax.persistence.spi.PersistenceProvider – user2708384 Aug 22 '13 at 20:41
  • Great, so finally they support it. In this case I would check if the javax.persistence.spi package is only ones in the OSGi container and the wirings. Maybe the aries-jpa stuff wires to another bundle's package than hibernate. In equinox you can easily check it via console with 'packages javax.persistence.spi' command. In felix it is another command but I do not know what it is :). If the wirings are good than maybe TransactionManager OSGi service is missing or DataSource/DataSourceFactory (depending on your persistence.xml) – Balazs Zsoldos Aug 22 '13 at 22:14
  • Also check if there are multiple packages and wirings for the other services. In case you do not know if you should search for DataSource or DataSourceFactory, share your persistence.xml without sensitive data and I will tell you :). – Balazs Zsoldos Aug 22 '13 at 22:16
  • I have another bundle as specified earlier "mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1" which exposes as shown below.hibernate-core & other bundles require .javax.persistence 1.2 or 2.0 version they use this bundle including aries-jpa for importing javax.persistence packages. javax.persistence,version=1.1.0;javax.persistence,version=2.0.0 javax.persistence.criteria,version=1.1.0;javax.persistence.criteria,version=2.0.0;javax.persistence.metamodel,version=1.1.0 javax.persistence.metamodel,version=2.0.0;javax.persistence.spi,version=1.1.0;javax.persistence.spi,version=2.0.0 – user2708384 Aug 22 '13 at 22:23
  • Here is my persistence.xml .. org.hibernate.ejb.HibernatePersistence osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/postgresds) com.igt.arcus.framework.domain.service.dao.Tenantentity true – user2708384 Aug 22 '13 at 22:25
  • In this case you need an OSGi service with interface DataSource and the service property you defined. Also you have to have a TransactionManager OSGi service. Be sure that aries and your persistence bundle wires to the same javax.transaction package. Due to the reason that you defined the element, be sure that the PersistenceProvider OSGi service has a service property with key 'javax.persistence.provider' and value 'org.hibernate.ejb.HibernatePersistence'. – Balazs Zsoldos Aug 22 '13 at 22:40
  • 1
    Yes i have a datasource bundles expose these required property..Also in blueprint i have mentioned the service properties with key & value ..below is the snippet.. – user2708384 Aug 22 '13 at 22:51
  • Could you please try replacing the aries=jpa-container with this one: https://repository.everit.biz/nexus/content/groups/public/org/everit/osgi/jpa/org.everit.osgi.jpa.container/1.0.1/org.everit.osgi.jpa.container-1.0.1-jdkbased.jar. If all active and it still does not work, could you please send the log somehow? This jar logs out it anything is missing. If you do not have an SLF4J deployed yet it has to be deployed as well (e.g. slf4j-api with slf4j-simple) – Balazs Zsoldos Aug 23 '13 at 08:10
  • missing dependency for ..org.everit.osgi.util.core.requisite,version=[1.0,2) -- Cannot be resolved org.apache.aries.quiesce.manager -- Cannot be resolved org.apache.aries.quiesce.participant -- Cannot be resolved – user2708384 Aug 23 '13 at 16:59
  • really sorry. You must install https://repository.everit.biz/nexus/content/groups/public/org/everit/osgi/util/org.everit.osgi.util.core/1.0.0/org.everit.osgi.util.core-1.0.0.jar as well that does the tracking of the requisites (TransactionManager and others). I hope I did not forget more dependencies – Balazs Zsoldos Aug 23 '13 at 17:40
  • org.apache.aries.quiesce.manager -- Cannot be resolved org.apache.aries.quiesce.participant -- Cannot be resolved ...still missing .. – user2708384 Aug 23 '13 at 17:42
  • Oops, it should be optional dependency of aries jpa container. I uploaded a fixed version to https://repository.everit.biz/nexus/content/groups/public/org/everit/osgi/jpa/org.everit.osgi.jpa.container/1.0.2/org.everit.osgi.jpa.container-1.0.2-jdkbased.jar. I hope nothing else is missing (I checked it carefully but I might have made a mistake) – Balazs Zsoldos Aug 23 '13 at 18:06
  • when i try to deploy the new bundle provided it does not even show up in my list on console ..? any idea wht might be wrong – user2708384 Aug 23 '13 at 20:25
  • Yes. The MANIFEST.MF was corrupt. I corrected it. The problem is that we use many packages from bundles instead of JDK so we always have to edit the MANIFEST.MF by hand to have a bundle that works without those bundles. Could you please try downloading from the same url again? I tested it and now the MANIFEST.MF is good. – Balazs Zsoldos Aug 23 '13 at 20:59
  • looks like it resolved my dependency issue ...so what exactly changed in this bundle which you have provided ?. – user2708384 Aug 24 '13 at 00:30
  • It logs (with the help of slf4j) more information about what is missing. If the jpa.container and your bundle is active and you have your persistence.xml at the good place you can see: "Cannot parse persistence descriptor" or "PersistenceProvider available for bundle" or "javax.persistence.provider property is missing from the service registration" or "Service reference XX with requisite id XX is available for...". But the most important: "Waiting for the following requiesites...". Do you see such logs? – Balazs Zsoldos Aug 24 '13 at 06:29
  • If you do not see any logs like I mentioned and all necessary bundles are active I can imagine too causes: Your persistence.xml is at the wrong place so your bundle is not picked up or SLF4J is configured not to show INFO level messages. – Balazs Zsoldos Aug 24 '13 at 06:32
  • looks like a class loading issue .when i drop my bundles first later make jpa container active no issues everything looks good but when jpa container is active & then i drop my bundles there is a dependency issue as waiting ..do we have any util bundle what would scan for any new bundles that get dropped so that it creates the entitymanager and resolves dependency ? – user2708384 Aug 26 '13 at 16:26
  • Which dependency is it waiting for? – Balazs Zsoldos Aug 26 '13 at 18:25
  • 10:35:37,111 | DEBUG | l Console Thread | AbstractServiceReferenceRecipe | r.AbstractServiceReferenceRecipe 143 | 7 - org.apache.aries.blueprint.core - 1.1.0 | Found initial references null for OSGi service (&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=tenant))(objectClass=javax.persistence.EntityManagerFactory)) – user2708384 Aug 27 '13 at 20:47
  • If you did not set otherwise you should get a timeout exception after five minutes (when a reference is not available for five minutes it is logged with ERROR scope). In case the service is available it is missing, probably the package javax.persistence is twice in your OSGi container and your blueprint bundle is not wired to the same one as the jpa.container.context bundle. – Balazs Zsoldos Aug 27 '13 at 21:04
  • But both my service bundle & JPA container bundle are using javax.persistence,version=1.1.0 from org.apache.geronimo.specs.geronimo-jpa_2.0_spec (162)..this does not happen when i start my bundle first later JPA container... – user2708384 Aug 27 '13 at 21:16
  • This means that you have that package twice? All bundles have to wire to the same package. I mean: the bundle that contains persistence.xml, the jpa.container bundle, the jpa.container.context bundle, jpa.blueprint bundle, hibernate bundles, the bundle that has jpa:context in it's blueprint.xml file – Balazs Zsoldos Aug 27 '13 at 21:50
  • Importing Bundles com.igt.arcus.framework.jta.arcus-framework-feature-service (335),hibernate-jpa-2.0-api (201),org.apache.aries.jpa.api (92),org.apache.aries.jpa.blueprint.aries (93),org.apache.aries.jpa.container (94),org.apache.aries.jpa.container.context (95),org.hibernate.core (132),org.hibernate.entitymanager (133),org.hibernate.envers (134),org.hibernate.osgi (130),org.springframework.context (89),osgi.enterprise (117)., – user2708384 Aug 27 '13 at 22:24
  • Exported Packages javax.persistence,version=1.1.0,javax.persistence,version=2.0.0,javax.persistence.criteria,version=1.1.0,javax.persistence.criteria,version=2.0.0 javax.persistence.metamodel,version=1.1.0 javax.persistence.metamodel,version=2.0.0 javax.persistence.spi,version=1.1.0 javax.persistence.spi,version=2.0.0 – user2708384 Aug 27 '13 at 22:27
  • One more question (I noted it a couple of times in my comments). How about javax.transaction package? Is it there twice? When there is a failure, how is the wiring. It happened to me many times that depending on the starting order wirings were done to the JDK javax.transaction package from some bundles while from other bundles the wirings was done to a bundle that contained javax.transaction package. jpa-container-context needs a javax.transaction package and if it is wired to the wrong place it will not start picking up the EntitManagerFactory services. – Balazs Zsoldos Aug 28 '13 at 00:04
  • javax.transaction,version=1.1.0 from org.apache.geronimo.specs.geronimo-jta_1.1_spec (57) -- Overwritten by Boot Delegation for bundle org.apache.aries.jpa.container.context.. – user2708384 Aug 28 '13 at 00:18
  • This is normally the cause. The JDK package has less classes in that package that is necessary. For example the TransactionManager class is not there. If the bundles wire to the JDK package, it will not work. You can exclude it from boot classpath, however you will meet the problem that javax.sql points to that package that also comes from JDK (boot classpath). I excluded the javax.sql.* packages as well from boot classpath and moved it out to be in a bundle with a nice version. Since that I had no such disturbing problems with the starting order. – Balazs Zsoldos Aug 28 '13 at 08:17
  • my concentration is more on jpa to work i can ignore the transaction from blueprint if needed ..? – user2708384 Aug 28 '13 at 17:43
  • Probably. However, in my experience JPA does not persist or merge any entity object outside of a transaction. The behavior was the same with Eclipselink and Hibernate. Maybe you can use it somehow with autocommit mode but I can't help with that. I always used it within transactions. – Balazs Zsoldos Aug 28 '13 at 18:41
0

The current aries jpa container jar 1.0.0 has a bug that makes it swallow exceptions on creating the EntityManager. A colleague of me opened the aries bug: https://issues.apache.org/jira/browse/ARIES-1160

I created a second patch that can be applied to the 1.0.0 sources to create a jar that correctly logs the exception. Check out the 1.0.0 tag of aries jpa container, apply the patch and build.

When you then run in karaf you should see the real source of the error.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64