users@glassfish.java.net

RE: using JPA from OSGI WAB in glassfish 3.1

From: Lena Svetlov <svetloe_at_hotmail.com>
Date: Thu, 3 Feb 2011 15:38:28 +0000

I found a list of glassfish tasks, and featureID OSGi-04-03 says "Need to support Hibernate and Open/JPA" ( http://wikis.sun.com/display/GlassFish/3.1OSGi )
Does it mean that JPA with hibernate will not work from my WAB?
If yes, when are you planning to solve it?


thank you
Lena
From: svetloe_at_hotmail.com
To: sanjeeb.sahoo_at_oracle.com
CC: users_at_glassfish.java.net
Subject: RE: using JPA from OSGI WAB in glassfish 3.1
Date: Thu, 3 Feb 2011 15:11:47 +0000








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.)

I deleted the "maven/com.test" folder from WAB (it caused the initial ZipException that I published). Now I get the following exception:
[#|2011-02-03T16:28:41.082+0200|SEVERE|glassfish3.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=17;_ThreadName=Thread-1;|Exception while preparing the app|#]

[#|2011-02-03T16:28:41.082+0200|SEVERE|glassfish3.1|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=17;_ThreadName=Thread-1;|The log message is null.
java.lang.ClassCastException
    at java.lang.Class.cast(Class.java:2990)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:173)
    at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:119)
    at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:202)
    at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:475)


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?


More details about my JPA configuration:
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="management" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/ManagementDbConnectionPool</jta-data-source>
        <properties>
            <!--property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/-->
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>
</persistence>

Part of domain.xml that configures connection-pool:
  <resources>
    <jdbc-connection-pool driver-classname="com.hp.btoe.core.dbdrivers.SQLServerDriver" res-type="java.sql.Driver" name="ManagementDbConnectionPool">
      <property name="MaxPooledStatements" value="5"></property>
      <property name="transactionMode" value="explicit"></property>
      <property name="SendStringParametersAsUnicode" value="false"></property>
      <property name="url" value="jdbc:mercury:sqlserver://labm3amrnddb13.devlab.ad:1433"></property>
      <property name="Password" value="mercurypw"></property>
      <property name="DatabaseName" value="scdam034_mng"></property>
      <property name="LoginTimeout" value="30"></property>
      <property name="User" value="sa"></property>
    </jdbc-connection-pool>
    <jdbc-resource pool-name="ManagementDbConnectionPool" jndi-name="jdbc/ManagementDbConnectionPool"></jdbc-resource>
.....
  </resources>
  <servers>
    <server name="server" config-ref="server-config">
      <resource-ref ref="jdbc/ManagementDbConnectionPool"></resource-ref>
...

    </server>
  </servers>


thanks for your help,
Lena


On Thu, Feb 3, 2011 at 12:28 PM, Sahoo <sanjeeb.sahoo_at_oracle.com> wrote:



  


Hi Lena,



Yes, I have only raised that bug against maven-bundle-plugin. I just to
came to know that there is now better support for WAB in
maven-bundle-plugin. I am yet to experiment the same. Let me do that
first and then I can advise how to organise the pom.xml to not have "."
in Bundle-ClassPath.



In the mean while, let's try to resolve the exception you are facing.
Can you hand edit the generated MANIFEST.MF and remove "." before
deploying the WAB to see if it fixes the issue? You can use some tool
like File Roller [1] to update the MANIFEST.MF in place or extract the
MANIFEST.MF, edit it and add it back using "jar uvfm" command. If
removing "." does not resolve the issue, can you share a test case with
us?



Thanks,

Sahoo



[1] http://fileroller.sourceforge.net/features.html



On Thursday 03 February 2011 03:32 PM, Lena Svetlov wrote:

  Hi
Sahoo,

  

Thanks for your answer.

  

1. "Embed-Dependency" tag in maven-bundle plugin fills in my
Bundle-ClassPath. As a result, MANIFEST.MF contains Bundle-ClassPath
with a long list of jars from WEB-INF/lib. I re-checked that it also
contains the JPA jar.

2. The "." in Bundle-ClassPath is a must, if I remove it the WAB
doesn't find the jars needed for Import-Package dependency. I found a
bug that describes the issue:
https://issues.apache.org/jira/browse/FELIX-1571

(Seems like you opened it? :) )

  

Any advice is appreciated.

  

thanks,

Lena

  

  On Wed, Feb 2, 2011 at 8:26 PM, Sahoo <sanjeeb.sahoo_at_oracle.com> wrote:

  
    Hi,

    

1. You said you have a JPA jar. Where is it packaged in the WAB? If it
is in WEB-INF/lib, then I don't see the corresponding entry in
Bundle-ClassPath.

2. Why do you have "." in Bundle-ClassPath. The top level entries in a
WAB do not have to take part in classloading, so you don't need that.

    

I think what you have is because of the way you have configured
maven-bundle-plugin. It is known fact that maven-bundle-plugin does not
go very well when one has to embed jars in a "war" type artifact.
Please see [1] and change your pom.xml accordingly. Before even you try
to change your pom.xml, I suggest you simply edit the MANIFEST.MF to
take care of #1 & #2 and see if it fixes your issue or not. If it
does, then change the pom.xml as suggested.

    

Thanks,

Sahoo

    

[1] http://www.mail-archive.com/users@felix.apache.org/msg04728.html

    

On Wednesday 02 February 2011 10:09 PM, Lena Svetlov wrote:
    
       (I am new in OSGI)

      

      

I am trying to access a JPA JAR from OSGI WAB in glassfish 3.1.

      

When I deploy the OSGI WAB with JPA jar, I get the exception:

[#|2011-02-01T18:29:10.035+0200|SEVERE|glassfish3.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=17;_ThreadName=Thread-1;|java.lang.RuntimeException:

java.util.zip.ZipException:
duplicate entry:
META-INF/maven/com.test/test-web/pom.properties at
org.glassfish.osgijavaeebase.OSGiBundleArchive$1.run(OSGiBundleArchive.java:366)
Caused

by:
java.util.zip.ZipException: duplicate entry:
META-INF/maven/com.test/test-web/pom.properties at
java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175)
at
java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92)
at
org.glassfish.osgijavaeebase.OSGiBundleArchive$1.run(OSGiBundleArchive.java:348)
|#]

      

      

More details about my JAR and WAB:

      

1) When the JPA JAR is included in non-OSGI WAR, it works correctly.
However OSGI WAB with this JPA JAR fails in deployment.

      

2) Below is a part from pom.xml that constructs a WAB:

      

                   
<artifactId>maven-bundle-plugin</artifactId>

                    <version>2.2.0</version>

                    <extensions>true</extensions>

                    <configuration>

                        <instructions>

                           
<Web-ContextPath>/testWab</Web-ContextPath>

                           
<Webapp-Context>/testWab</Webapp-Context>

                            <Export-Package/>

                            <Export-EJB>all</Export-EJB>

                            <DynamicImport-Package>javax.*,
org.xml.sax, org.xml.sax.*, org.w3c.*</DynamicImport-Package>

                           
<Bundle-ClassPath>.,WEB-INF/classes/</Bundle-ClassPath>

                           
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>

                           
<Embed-Directory>WEB-INF/lib</Embed-Directory>

                           
<Embed-Transitive>true</Embed-Transitive>

                           
<Import-Package>com.test.integration.service.*;version="1.0.0",
com.test.adapter.*;version="1.0.0",org.osgi.framework,
org.osgi.util.tracker</Import-Package>

                        </instructions>

                    </configuration>

      

Please consult