14 Replies Latest reply on Jun 21, 2007 5:25 PM by soluble

    Glassfish example and the entity converter.

    soluble

      If I add the entity converter initialization config to components.xml in the \jboss-seam-1.2.1.GA\examples\glassfish example I find that deploying the app for the first time works. However, deploying subsequent times fails with many errors produced in the log files (detailed below).

      To use the entity converter, the following changes need to be made to the Glassfish example:

      The following needs to be added to components.xml:

       <core:entity-manager-factory name="dbFactory"
       persistence-unit-name="bookingDatabase"/>
       <core:managed-persistence-context name="entityManager"
       auto-create="true" entity-manager-factory="#{dbFactory}"/>
       <core:entity-converter entity-manager="${entityManager}"/>
      

      and the persistence.xml needs to use a JTA factory:
      <?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_1_0.xsd"
       version="1.0">
       <persistence-unit name="bookingDatabase" transaction-type="JTA">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>jdbc/__default</jta-data-source>
       <properties>
      
       <property name="hibernate.dialect"
       value="org.hibernate.dialect.DerbyDialect"/>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.transaction.flush_before_completion" value="true"/>
       <property name="hibernate.transaction.manager_lookup_class"
       value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
       <property name="hibernate.cache.provider_class"
       value="org.hibernate.cache.HashtableCacheProvider"/>
       </properties>
       </persistence-unit>
      </persistence>
      

      The first time I deploy the application, the context starts and I have a functioning Hotel Booking system. Subsequent undeploy/deploy cycles, without changing any code results in the following errors and an unfunctioning application.

      ...
      Parent -> EJBClassLoader :
      urlSet = []
      doneCalled = false
       Parent -> java.net.URLClassLoader@5c3987
      
       was requested to find resource org/hibernate/ejb/persistence_1_0.xsd after done was invoked from the following stack trace
      java.lang.Throwable
       at com.sun.enterprise.loader.EJBClassLoader.findResource(EJBClassLoader.java:458)
       at java.lang.ClassLoader.getResource(ClassLoader.java:977)
       at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1159)
       at com.sun.enterprise.loader.EJBClassLoader.getResourceAsStream(EJBClassLoader.java:795)
       at org.hibernate.util.DTDEntityResolver.resolveInHibernateNamespace(DTDEntityResolver.java:78)
       at org.hibernate.cfg.EJB3DTDEntityResolver.resolveEntity(EJB3DTDEntityResolver.java:53)
       at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(EntityResolverWrapper.java:107)
       at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntity(XMLEntityManager.java:1100)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.resolveDocument(XMLSchemaLoader.java:595)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2403)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1753)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685)
       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3084)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:645)
       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
       at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
       at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
       at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
       at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:70)
       at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:79)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:212)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:96)
       at org.jboss.seam.core.EntityManagerFactory.startup(EntityManagerFactory.java:74)
      ...
      

      ...
      Parent -> EJBClassLoader :
      urlSet = []
      doneCalled = false
       Parent -> java.net.URLClassLoader@5c3987
      
       was requested to find class sun.net.www.protocol.http.HttpURLConnection.LogStrings after done was invoked from the following stack trace
      java.lang.Throwable
       at com.sun.enterprise.loader.EJBClassLoader.findClassData(EJBClassLoader.java:707)
       at com.sun.enterprise.loader.EJBClassLoader.findClass(EJBClassLoader.java:627)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2370)
       at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1400)
       at java.util.ResourceBundle.findBundle(ResourceBundle.java:1365)
       at java.util.ResourceBundle.findBundle(ResourceBundle.java:1294)
       at java.util.ResourceBundle.findBundle(ResourceBundle.java:1294)
       at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1236)
       at java.util.ResourceBundle.getBundle(ResourceBundle.java:964)
       at java.util.logging.Logger.findResourceBundle(Logger.java:1298)
       at java.util.logging.Logger.setupResourceInfo(Logger.java:1326)
       at java.util.logging.Logger.getLogger(Logger.java:326)
       at com.sun.enterprise.server.logging.BaseLogManager.doInitializeLogger(BaseLogManager.java:125)
       at com.sun.enterprise.server.logging.BaseLogManager.addLogger(BaseLogManager.java:195)
       at java.util.logging.Logger.getLogger(Logger.java:278)
       at sun.net.www.protocol.http.HttpURLConnection.<clinit>(HttpURLConnection.java:63)
       at sun.net.www.protocol.http.Handler.openConnection(Handler.java:44)
       at sun.net.www.protocol.http.Handler.openConnection(Handler.java:39)
       at java.net.URL.openConnection(URL.java:945)
       at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:651)
       at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1316)
       at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDocumentEntity(XMLEntityManager.java:1268)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.setInputSource(XMLDocumentScannerImpl.java:280)
       at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:409)
       at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:491)
       at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser.parse(SchemaDOMParser.java:510)
       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1802)
       at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2408)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1753)
       at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685)
       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3084)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:912)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:645)
       at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
       at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:508)
       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
       at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
       at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
       at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
       at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
       at org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:70)
       at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:79)
       at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:212)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:96)
       at org.jboss.seam.core.EntityManagerFactory.startup(EntityManagerFactory.java:74)
      

      and so on, ending with
      PWC1306: Context startup failed due to previous errors

      Does anyone have any idea why this might be? It severely affects the code/debug cycle as each time a developer will need to undeploy, restart Glassfish and then redeploy to get things working.

      This is a follow on from a previous post (http://www.jboss.org/index.html?module=bb&op=viewtopic&t=110033).
      I am using Glassfish v2 build 48 and jboss-1.2.1.GA.

      Thanks in advance.

        • 1. Re: Glassfish example and the entity converter.
          soluble

          I wonder if the lack of replies means that no one gets this problem or everyone gets it but does not know how to solve it... It is a pitty because it makes Glassfish completely impractical as a platform for using wonderful Seam.

          • 2. Re: Glassfish example and the entity converter.
            gavin.king

            So, I don't quite understand what you're looking for here. You have found some kind of possible incompatibility between Hibernate and GlassFish, that does not appear to be in any way related to Seam.

            Why do you think you will find anyone in the Seam forum who can solve the problem?

            • 3. Re: Glassfish example and the entity converter.
              soluble

              Thanks for the reply. I thought it was possible that my problem was related to Seam, this is why I posted on the form: I assumed that at some point with the Glassfish example javax.persistence.Persistence.createEntityManagerFactory would be called for database access. Therefore, why should the core:entity-manager-factory component which explicitly calls Persistence.createEntityManagerFactory cause my problems unless the component was incompatible with Glassfish.

              However, as it is obvious to you that Seam plays no part in my problems and I am one step closer to solving them.

              Thanks again.

              • 4. Re: Glassfish example and the entity converter.
                gavin.king

                OK, no problem.

                • 5. Re: Glassfish example and the entity converter.
                  dochez


                  It looks like an incompatibility between Hibernate and GlassFish. In most cases, we generate this message when an application was undeployed (or redeployed) and someone still holding a reference to the old application's class loader is trying to load classes or resources from it.

                  Emmanuel Bernard pointed me to the thread, so we have the right people involved to find the problem.

                  could you answer the following questions :

                  which version of glassfish and hibernate are u using ?

                  thx, jerome

                  • 6. Re: Glassfish example and the entity converter.
                    soluble

                    I am using I am using Glassfish v2 build 48 and the Hibernate that comes bundled with jboss-seam-1.2.1.GA. According to the MANIFEST.MF file in \jboss-seam-1.2.1.GA\hibernate\lib\hibernate3.jar it is version 3.2.1.ga.

                    Thanks for the help, it is much appreciated.

                    • 7. Re: Glassfish example and the entity converter.
                      epbernard

                      How do you "deploy" HEM in Glassfish? Is it in your app, or in the Glassfish classpath?


                      Seam is using the JavaEE classloaders in a traditional way, I don't see how the CL could be kept around.

                      • 8. Re: Glassfish example and the entity converter.
                        soluble

                        The app I am using is the glassfish example in \jboss-seam-1.2.1.GA\examples\glassfish. The ant build script provided with the example collects all the hibernate*.jar files in \jboss-seam-1.2.1.GA\hibernate\lib and adds them to the jboss-seam-glassfish.ear file it creates. Therefore, the I presume the answer is that the HEM is deployed with the app.

                        • 9. Re: Glassfish example and the entity converter.
                          hongzhang

                          soluble: can you provide the set of the instructions to reproduce this problem? I know you mentioned "\jboss-seam-1.2.1.GA\examples\glassfish", when do I download this? Are the full set of instructions all included in the sample doc?

                          • 10. Re: Glassfish example and the entity converter.
                            soluble

                            Hi hongzhang, the instructions to reproduce the problem are as follows:

                            1) Download and install Glassfish v2 https://glassfish.dev.java.net/downloads/v2-b48.html. I am using the Windows version build 48.

                            2) Download and extract JBoss Seam 1.2.1 GA http://labs.jboss.com/jbossseam/download.

                            On my computer Glassfish is in c:\glassfish and Seam is in c:\java\jboss-seam-1.2.1.GA.

                            3) Start glassfish and its JavaDB if not started. Using the command line this is:

                            c:\glassfish\bin\asadmin start-domain
                            c:\glassfish\bin\asadmin start-database
                            


                            4) Build the Glassfish example in seam using ant:
                            cd c:\java\jboss-seam-1.2.1.GA\examples\glassfish
                            c:\glassfish\bin\asant
                            


                            5) Deploy the ear file to Glassfish:
                            cd c:\java\jboss-seam-1.2.1.GA\examples\glassfish
                            c:\glassfish\bin\asadmin deploy build\jboss-seam-glassfish.ear
                            


                            With this step, the application should work fine and you should be able to login via a web browser http://localhost:8080/jboss-seam-glassfish/. Username demo, password demo. Note that due to a bug in the example, it will not work successfully with Firefox.

                            Now to reproduce the problems I am having:

                            1) You will need to add the following component config to your components.xml file located in c:\java\jboss-seam-1.2.1.GA\examples\glassfish\resources\WEB-INF:
                            <core:entity-manager-factory name="dbFactory"
                             persistence-unit-name="bookingDatabase"/>
                             <core:managed-persistence-context name="entityManager"
                             auto-create="true" entity-manager-factory="#{dbFactory}"/>
                             <core:entity-converter entity-manager="${entityManager}"/>
                            


                            2) Add a Hibernate JTA factory by replacing your persistence.xml file content located in c:\java\jboss-seam-1.2.1.GA\examples\glassfish\resources\META-INF with:
                            <?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_1_0.xsd"
                             version="1.0">
                             <persistence-unit name="bookingDatabase" transaction-type="JTA">
                             <provider>org.hibernate.ejb.HibernatePersistence</provider>
                             <jta-data-source>jdbc/__default</jta-data-source>
                             <properties>
                             <property name="hibernate.dialect"
                             value="org.hibernate.dialect.DerbyDialect"/>
                             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                             <property name="hibernate.show_sql" value="true"/>
                             <property name="hibernate.transaction.flush_before_completion" value="true"/>
                             <property name="hibernate.transaction.manager_lookup_class"
                             value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
                             <property name="hibernate.cache.provider_class"
                             value="org.hibernate.cache.HashtableCacheProvider"/>
                             </properties>
                             </persistence-unit>
                            </persistence>
                            


                            3) Clean, rebuild and redeploy the example:
                            cd c:\java\jboss-seam-1.2.1.GA\examples\glassfish
                            c:\glassfish\bin\asant clean
                            c:\glassfish\bin\asant
                            c:\glassfish\bin\asadmin deploy build\jboss-seam-glassfish.ear
                            

                            This should also allow the app to work.

                            4) However, try and redeploy again without making any changes:
                            cd c:\java\jboss-seam-1.2.1.GA\examples\glassfish
                            c:\glassfish\bin\asadmin deploy build\jboss-seam-glassfish.ear
                            

                            You will find that the application will not start complaining of the errors I indicated in my previous posts. The only way I have found to get the example working again is to undeploy, restart glassfish and then deploy:

                            cd c:\java\jboss-seam-1.2.1.GA\examples\glassfish
                            c:\glassfish\bin\asadmin undeploy jboss-seam-glassfish
                            c:\glassfish\bin\asadmin stop-domain
                            c:\glassfish\bin\asadmin start-domain
                            c:\glassfish\bin\asadmin deploy build\jboss-seam-glassfish.ear
                            


                            At the request of epbernard I tried using the latest version of HEM with the example but that didn't seem to make much difference. I hope all these instructions make sense to you!

                            • 11. Re: Glassfish example and the entity converter.
                              hongzhang

                              Thanks for the detailed instructions! I was able to reproduce the problem on my box now. I will look into this and let you know what I find out.

                              • 12. Re: Glassfish example and the entity converter.
                                sahoo

                                Yes, it is a bug - a bug in the spec supplied javax.persistence.Persistence.class. There is a work around available for you. Instead of packaging Hibernate classes in the ear file, please put them in GlassFish/lib directory and restart the server. That will fix the issue. Now read on, what is the bug...

                                The spec supplied javax.persistence.Persistence.class (https://glassfish.dev.java.net/source/browse/glassfish/persistence-api/src/java/javax/persistence/Persistence.java?rev=1.8&view=markup) has a static variable defined like this:

                                protected static final Set<PersistenceProvider> providers = new HashSet<PersistenceProvider>();
                                

                                In createEntityManagerFactory() method, it uses currentThread.getContextClassLoaded() to search for all the persistence providers and stores them in that variable. Obviously, this is an optimization attempt, but it is not free from trouble. One of the scenarios where it does not always work is in your case, where the providers are bundled in the application ear/jar/war.
                                First time, you deploy the app, providers variable is populated with HibernatePersistence.class loaded by the application class-loader that the app was associated with at that point of time. When you redeploy, the app is now associated with a new class loader, and we expect the old class loader to be garbage collected. But, because of this providers variable, the old HibernatePersistence.class is used. GlassFish is written to protect against it, so we detect the situation and disallow the class loading. Hence you see that exception.

                                I have been able to fix this issue by patching Persistence.class. I will file an issue in GlassFish and see how we can address the spec supplied class. In the mean while, you should be able to use the work around suggested earlier.

                                Thanks,
                                Sahoo

                                • 13. Re: Glassfish example and the entity converter.
                                  hongzhang

                                  Quite a conicidence, there was a glassfish issue filed for this problem yesterday :-)
                                  https://glassfish.dev.java.net/issues/show_bug.cgi?id=3229

                                  • 14. Re: Glassfish example and the entity converter.
                                    soluble

                                    Thank you all for your help!