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/

Some background on Aries + OpenJPA setup is in this blog:
http://hwellmann.blogspot.de/2010/09/openjpa-and-osgi.html

Regards,
Harald

Reply via email to