users@glassfish.java.net

Re: using JPA from OSGI WAB in glassfish 3.1

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Thu, 03 Feb 2011 21:18:25 +0530

On Thursday 03 February 2011 08:41 PM, Lena Svetlov wrote:
> Hi Sahoo,
>
> (I tried removing the "." from MANIFEST.MF, as a result I received
> "ClassNotFoundException" for classes that were imported in
> "Import-Package". So I rolledback this change.)
This indicates you have really packaged some classes in the root of your
WAB which is actually not a good thing as that can lead to security
hole. The reason being the root of the WAB is also the docroot, so any
one can issue a GET request for your classes and your web app will serve
the class bytes to them. You should really package everything in your
WAB just like you do in a WAR which means classes should be kept in
WEB-INF/classes/ or some jar in WEB-INF/lib/. Anyway, that's not a
mandatory thing to do, just a recommendation. I won't be surprised if
you say that you are not finding it easier to package the WAB using
maven-bundle-plugin. As I said, I shall try to experiment with the new
plugin and let you know if there is any improvement.
It will help if you can either send me a test wab or the following
information in order for me to debug your initial problem (ZipException):
a) structure of your WAB as printed by "jar tvf foo.war" ( I am not
interested in static contents, only classes or jar files)
b) MANIFEST.MF of your WAB.

>
> I deleted the "maven/com.test" folder from WAB (it caused the initial
> ZipException that I published). Now I get the following exception:
> In debug I saw that the exception comes from casting
> "*org.hibernate.ejb.HibernatePersistence*" to
> "*javax.persistence.spi.PersistenceProvider*" (screenshot is attached)
>
> I suspect that the location of hibernate / drivers jars is wrong (I
> put the hibernate jars inside a WAB, and drivers jars inside the
> glasfish/lib).
> What is the correct location?
glassfish/lib is alright, but glassfish/domain/domain1/lib/ is a better
alternative for JDBC drivers, for JDBC drivers are not needed by
GlassFish itself - they are only used in the context of an application.
I don't think deployment has gone to the extent of using JDBC, so
drivers are not coming to picture yet. The reason for ClassCastException
seems unrelated to driver location. It is possible that you have
actually embedded javax.persistence.* classes in your WAB and I don't
see them being imported statically by your WAB. You only have
DynamicImport-Package: javax.*. If a bundle dynamically imports a Java
package and also packages the Java package, then search order in OSGi
does not get to use DynamicImport-Package header, as it would have
located the package from the bundle local space. So, you should either
stop bundling javax packages in your WAB or import them using
Import-Package. Hope this solves your issue.

BTW, why don't you just use EclipseLink which comes bundled with
GlassFish and then you don't have to bundle the provider inside your
WAB. I should also mention that we have not actually tested use of
third-party JPA providers in a WAB. We support use of EclipseLink which
is the default JPA provider in GlassFish.

Thanks,
Sahoo