Hi, I would like to thank for David and for the answer. My questions may seem to be a bit silly however I have a strong reason why I ask them. I develop several re-usable bundles where multiple applications may use the same util classes and the same entity classes.
An example: Authorization takes place in only three tables: Resource, Permission and PermissionInheritance. Permission may be defined between two resources and a resource that inherits from another resource will get the parent's permissions. Anything can be a resource. A user, a car, any item in an application. Why is this good? It is good because queries created with JPA Criteria API can be enhanced with util functions to contain permission checks. Any FROM or JOIN part of the query can be automatically extended by taking the same query snippet to the WHERE part and the difficulties of query enhancement is hidden from developers. There are other use cases like this (e.g. localization). What happens here? I have application A and application B. Both of them use the Entity classes from PermissionManagement and both of them use the Permission-core bundle to have the query enhancement as well. If I copy the classes from PermissionEntity to AEntity and BEntity bundle as well I will not be able to use the Util functions from permission-core as it will not know the entity classes and more importantly the static metamodels. Therefore we have several Entity bundles that contain reusable Entity classes and one PersistenceUnit bundle for each application. Normally the PersistenceUnit bundle contains only a persistence.xml, some application related Entity classes and some import-package wiring to the re-usable entity bundles. We worked first with EclipseLink under Glassfish (it was already there so we used it) with Aries JPA Container and it worked. However EclipseLink fails on more complex Criteria Queries as it generates wrong native SQL. Therefore we moved to Hibernate with Aries JPA Container and I created our own Hibernate bundle and adapter (like Eclipselink adapter in aries-jpa project). It seems to work and it can handle more complex queries as well. A couple of day ago here someone said that OpenJPA fits much more to the OSGI word so I tried to use it. However it seemed to me that I will meet some problems because of this weaving stuff and that is why I am not sure that I can use it with our use-cases. My problem with weaving is that I do not thing it is OSGI friendly at all. Somewhere I read that a bundle is not well written if the start order of the bundles matter. When weaving is used it means that it has to be a java agent or the bundle that does the weaving has to start first for sure. I think agent stuff should be used only for generating coverage reports or attaching a profiler but not for technologies that run inside an application. Compile time enhancement may be better a bit but that raised my questions: Can I use an enhanced class with other PersistenceProviders? OpenJPA has to be in the OSGI container if the classes are enhanced at compile time but other Persistence Provider is used by the application?... I saw that a draft came out about OSGI-Subsystems but the draft spec was not really clear to me at some parts. I see that Aries developers take a lot of energy of implementing it. I have the feeling that subsystems is something like going back to WAR and EAR file development (long deploy time, robust applications) but within an OSGI container. I am not sure if two application needs the same Entity logic they should both deploy it under their subsystems but they should reuse the same entity bundle in their persistence units. Well the last two chapters is only my opinion and I am not even sure I am not wrong :). I would be very happy if someone convinced me about the opposite. Balazs Zsoldos On Wed, May 30, 2012 at 7:26 PM, Harald Wellmann <[email protected]>wrote: > Am 29.05.2012 06:49, schrieb Balázs Zsoldos: > >> >> * Shall import-package used for a bundle that has OpenJPA compile time >> enhancement? >> > > For the model classes, or for the additional package dependencies added by > the enhancer? If the framework supports weaving hooks, the additional > dependencies should be added automagically. > > * If an Entity class is enhanced by OpenJPA, can it be used in >> multiple Persistence Units? >> > > Are you trying to follow the OSGi Enterprise JPA spec, or just rolling > your own OSGi + JPA environment? The spec requires all model classes of a > persistence unit to be in the same persistence bundle. > > I tried using entity classes from multiple bundles with OpenJPA, which may > or may not work, depending on the context. For some join queries containing > more than one class name, I sometimes had classloader errors. > > * A class enhanced by OpenJPA can be used with other technologies like >> Hibernate? >> > > OpenJPA bytecode enhancement creates a compile-time and run-time > dependency of the enhanced bytecode on OpenJPA. I.e. you cannot compile > MyDAO.java on top of mymodel.jar containing your enhanced entity model > without OpenJPA on the classpath. > > > * An enhanced class needs OpenJPA present in the runtime even if we >> >> use it with a different provider like Hibernate or EclipseLink? >> Practically if import-package is necessary, could it be optional? >> > > Hmm, never tried that. But even if Hibernate or Eclipselink could deal > with or ignore the enhanced bytecode, I suspect some other services might > get confused by two persistence providers in the system. > > > >> If anybody knows the answer to these questions please let me know! I >> think I will have to read a bit about the enhancement of OpenJPA what it >> does exactly and how it does it. >> >> > OSGi + JPA can be rather frustrating because whichever way you turn, some > bits and pieces are missing: > > - Hibernate has no OSGi support at all. > > - Both Hibernate and Eclipselink have too many serious bugs in core JPA > functions, which is why I favour OpenJPA, in spite of other peculiarities. > > - OpenJPA compile-time enhancement is a major nuisance and breaks > compatibility with other persistence providers (my ceterum censeo with > OpenJPA...) > > - Load-time weaving is great, OpenJPA supports it, but not all containers > do. It works fine with GlassFish 3.1 (with plain old WARs, but probably not > in OSGI mode, never tried.) > > - About a year ago, I had a working demo with Equinox 3.7-SNAPSHOT + > OpenJPA 2.1 + Aries 0.4-SNAPSHOT using load-time weaving. The problem with > Aries is they seem to be too busy coding to release anything. > > The latest Aries JPA release 0.3 of Jan 2011(!) does not support load time > weaving. Last time I tried, the trunk didn't even build, and the new > version-per-module approach adds to the confusion. > > - I also tried Eclipse Gemini at about the same time and dismissed it > because it forces explicit Spring package dependencies on your application > bundles, which really should be an implementation detail of the container. > > You can find some sample code, both with Aries and Gemini, here: > http://code.google.com/p/osgi-**enterprise/<http://code.google.com/p/osgi-enterprise/> > > Some background on Aries + OpenJPA setup is in this blog: > http://hwellmann.blogspot.de/**2010/09/openjpa-and-osgi.html<http://hwellmann.blogspot.de/2010/09/openjpa-and-osgi.html> > > Regards, > Harald >
