8 Replies Latest reply on Jun 7, 2007 9:15 PM by epbernard

    Trouble Using <s:convertEntity/> on Glassfish

    soluble

      I am using Glassfish v2 build 48 and am having difficulty using <s:convertEntity/>. My setup is basically the glassfish example in jboss-1.2.1.GA which I have imported into NetBeans 5.5.1.

      The first error I got when trying to use <s:convertEntity/> in a facelet was:

      ERROR [EntityConverter] Entity Manager not found

      So I searched the web and realised I should add the following to my components.xml file:

      <core:entity-manager-factory name="bookingDatabase"/>
      <core:managed-persistence-context name="em" auto-create="true" entity-manager-factory="#{bookingDatabase}"/>


      I did this and got the following when I tried to deploy the app to glassfish: (Note that this is just an exert of the stack trace.)

      Parent -> EJBClassLoader :
      urlSet = []
      doneCalled = false
      Parent -> java.net.URLClassLoader@126a29c
      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)


      Has anyone got any idea about where I go from here?

      Thanks,
      Jon

        • 1. Re: Trouble Using <s:convertEntity/> on Glassfish
          thejavafreak

          Are you using Toplink or Hibernate?

          I think the problem comes from your persistence layer. Go and check your persistence.xml settings or paste it here so others can help you finding out the solution

          • 2. Re: Trouble Using <s:convertEntity/> on Glassfish
            soluble

            My persistence layer uses Hibernate as the provider and is the exact one from the Glassfish example that comes with the jboss-seam-1.2.1.GA download:

            <?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">
             <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.cache.provider_class"
             value="org.hibernate.cache.HashtableCacheProvider"/>
             </properties>
             </persistence-unit>
            </persistence>
            


            In fact the only difference my app has to the glassfish example is that I have added a few more session beans and facelets.

            I should also mention that a few more stack traces also come up such as:

            Parent -> EJBClassLoader :
            urlSet = []
            doneCalled = false
             Parent -> java.net.URLClassLoader@ce16ad
             was requested to find class org.hibernate.event.EventListenersBeanInfo 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)
            ...
            


            and

             Parent -> EJBClassLoader :
            urlSet = []
            doneCalled = false
             Parent -> java.net.URLClassLoader@ce16ad
             was requested to find class org.hibernate.util.CloneableBeanInfo 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)
            ...
            


            and

            javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not instantiate dialect class
             at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
            ...
            Caused by: java.lang.ClassCastException: org.hibernate.dialect.DerbyDialect cannot be cast to org.hibernate.dialect.Dialect
             at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:78)
            ...
            


            I hope this helps.

            • 3. Re: Trouble Using <s:convertEntity/> on Glassfish
              soluble

              Looking futher at the configuration I have discovered that just adding

              <core:entity-manager-factory name="dbFactory" persistence-unit-name="bookingDatabase"/>
              to the components.xml file in the Glassfish example of jboss-seam-1.2.1.GA causes all the errors in the previous post. On examination of the org.jboss.seam.core.EntityManagerFactory source code I found that there is a requirement for EntityManagerFactory to use the Seam microcontainer:
              @Scope(ScopeType.APPLICATION)
              @Intercept(NEVER)
              @Startup(depends="org.jboss.seam.core.microcontainer")
              public class EntityManagerFactory
              {
              
               private String persistenceUnitName;
              ...
              

              I am pretty certain that I should not need to use the microcontainer in Glassfish v2 as it is EE compliant. Could the problem I am having be related to
              http://www.jboss.com/index.html?module=bb&op=viewtopic&t=106649
              and
              http://jira.jboss.org/jira/browse/JBSEAM-1195

              If so is there any way around it or will I have to use the Seam microcontainer with Glassfish to get <s:convertEntity/> working?

              • 4. Re: Trouble Using <s:convertEntity/> on Glassfish
                gavin.king

                You have misunderstood the semantics of @Startup(depends=...).


                Check the JavaDoc, and the line about "if it is installed".


                Bottom line: you do not need MC to use an SMPC in glassfish.

                • 5. Re: Trouble Using <s:convertEntity/> on Glassfish
                  soluble

                  Thanks for the clarification. Seam really does have some neat features!

                  I am trying to get to the root of my problem so have reverted to using the "jboss-seam-1.2.1.GA/examples/glassfish" example. I tried adding

                  <core:entity-manager-factory name="dbFactory" persistence-unit-name="bookingDatabase"/>
                  to the components.xml file expecting the example app to still work. However I got the following error:
                  javax.persistence.PersistenceException: java.lang.NullPointerException
                   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:252)
                   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)
                   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  ...
                  

                  Does anyone know what config I should tweak to get the entity-manager-factory working on the glassfish example? I suspect it is a visibility problem with the persistence.xml file and associated entities. However, it is late and I would like to stop experimenting for the night. Maybe once that works, I can try thinking about <s:convertEntity/> again. ;)



                  • 6. Re: Trouble Using <s:convertEntity/> on Glassfish
                    epbernard

                    Hi,
                    Before digging more, try and update to HEM 3.3.1
                    Download the package and copy

                    cp $HEM_HOME/lib/hibernate-annotations.jar $JBOSSAS_HOME/client
                    cp $HEM_HOME/lib/hibernate-annotations.jar $HEM_HOME/server/default/lib
                    cp $HEM_HOME/lib/hibernate-entitymanager.jar $JBOSSAS_HOME/server/default/lib
                    cp $HEM_HOME/lib/hibernate-commons-annotations.jar $JBOSSAS_HOME/server/default/lib
                    cp $HEM_HOME/lib/hibernate-validator.jar $JBOSSAS_HOME/server/default/lib

                    Or accordingly for glassfish

                    • 7. Re: Trouble Using <s:convertEntity/> on Glassfish
                      soluble

                      epbernard, thank you for your advice. I had a go but it did not seem to fix my problem. The Glassfish log file just came up with another error again resulting in a Context startup failed due to previous errors.

                      However, I did manage to get <s:convertEntity/> working on the Glassfish example in jboss-seam-1.2.1.GA! In the process it did expose peculiar behaviour of Glassfish and/or Seam which I though might be beneficial to share.

                      Apart from adding an EVENT scoped stateless bean, persistence entity and facelet file to test the <s:convertEntity/> the only changes I made to the example configuration were as follows:

                      1) persistence.xml - I added a transaction type and transaction manager to the persistence unit:

                      ...
                       <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.cache.provider_class"
                       value="org.hibernate.cache.HashtableCacheProvider"/>
                       <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
                       </properties>
                       </persistence-unit>
                      ...
                      


                      2) components.xml - I added the config to create an entity manager factory, create an entity manager and then pass it to the entity converter. (Looking at the code, I probably do not need to pass the entity manager to the entity converter.)
                      ...
                       <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}"/>
                      ...
                      



                      You may realise that this is almost the setup I had with the first post of this thread (apart from the transaction manager). The peculiar behaviour is that in order to add the changes I wanted to the components.xml file, I cannot simply rebuild the app with ant and do the following:

                      asadmin undeploy jboss-seam-glassfish
                      asadmin deploy jboss-seam-glassfish.ear

                      This always produces a Context startup failed due to previous errors with varying stack traces in the Glassfish server.log.

                      I must do the following to guarantee successful deployment:

                      asadmin undeploy jboss-seam-glassfish
                      asadmin stop-domain
                      <Manually delete \glassfish\domains\domain1\applications\j2ee-apps\jboss-seam-glassfish directory>
                      asadmin start-domain
                      asadmin deploy jboss-seam-glassfish.ear

                      Therefore I cannot hot deploy. To me it seems like a bug in Glassfish which Seam exposes that forces me to stop and start the domain in order to redeploy the application. Something is probably remaining within Glassfish after the undeploy command. Is anyone able to reproduce this problem? (Just get the glassfish example, add the transaction manager to the persistence.xml file and deploy to glassfish. Then add the changes to the components.xml file and redeploy without restarting. The example should fail to work.)

                      • 8. Re: Trouble Using <s:convertEntity/> on Glassfish
                        epbernard

                        If you manage to reproduce the NullPointerException in the EntityManager 3.3.x, I'm interested in the stacktrace, so that I can understand what's going on