2 Replies Latest reply on Mar 14, 2009 5:56 AM by Dan Allen

    Problems configuring Seam 2.1.x with Glassfish+Derby

    Andre Wilms Newbie
      Hey Seam-experts,

      I'm a newbie regarding Seam so please forgive my dumb question. I got the book "Seam In Action" (Dan Allan) and study the examples project "open18". Everythings works fine with JBoss 4.2.2 and the H2 database. I'm impressed.

      The future project at work needs Glassfish, though. So I tried to migrate that seam-gen created projected to the current Glassfish/Derby versions. I used the instructions from various sources but none of them really work for me.

      So when I try to start the application in my browser, I get a stacktrace with a few interesting lines:

      Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManager
      ...
      Caused by: java.lang.IllegalArgumentException: could not set property value: entityManager.setPersistenceUnitJndiName
      ...
      Caused by: java.lang.IllegalArgumentException: Could not invoke method by reflection: ManagedPersistenceContext.setPersistenceUnitJndiName(java.lang.String) with parameters: (org.hibernate.ejb.EntityManagerFactoryImpl) on: org.jboss.seam.persistence.ManagedPersistenceContext

      The components.xml contains these lines (and many more):

      <transaction:ejb-transaction/>
        
      <core:init debug = "@debug@"
      jndi-pattern = "java:comp/env/open18/#{ejbName}/local" />
          
      <core:manager concurrent-request-timeout = "500" 
                    conversation-timeout = "120000" 
                    conversation-id-parameter = "cid"
                    parent-conversation-id-parameter = "pid" />
        
      < persistence:entity-manager-factory
        name = "open18EntityManagerFactory"
        persistence-unit-name = "open18" />
        
      < persistence:managed-persistence-context
        name = "entityManager"
        auto-create = "true"
        persistence-unit-jndi-name = "#{open18EntityManagerFactory}" />

      Here are the last few lines of the web.xml:

      ejb-local-ref>
        <ejb-ref-name>open18/EjbSynchronizations/local</ejb-ref-name> 
        <ejb-ref-type>Session</ejb-ref-type>
        <local-home></local-home>
        <local>
          org.jboss.seam.transaction.LocalEjbSynchronizations
        </local>
        <ejb-link>EjbSynchronizations</ejb-link>
      </ejb-local-ref >

      And here is the important part of the persistence-dev.xml:

      <persistence-unit name="open18">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>jdbc/__default</jta-data-source>
        <properties>
          <!-- The following two properties are for Glassfish  -->
          <property name = "hibernate.dialect"  
           value = "org.hibernate.dialect.DerbyDialect" />
          <property name ="hibernate.transaction.manager_lookup_class"
           value = "org.hibernate.transaction.SunONETransactionManagerLookup" />
          <property name = "hibernate.hbm2ddl.auto" value = "update" />
          <property name = "hibernate.show_sql" value = "true" />
          <property name = "hibernate.format_sql" value = "true" />
          <property name = "hibernate.cache.provider_class"
           value = "org.hibernate.cache.HashtableCacheProvider" />
        </properties>
      </persistence-unit>

      Does anybody know how to fix our problem? Any (!) help is VERY appreciated.  Two collegues and I looked in every corner of the internet but we just can't find the solution ..

      Thank you,
      Andre
        • 1. Re: Problems configuring Seam 2.1.x with Glassfish+Derby
          Dan Allen Master

          Your problem is that you are trying to pass the EntityManagerFactory component to the persistence-unit-jndi-name property, which is just nonsensical. You are using the wrong attribute name.


          Here's what you have:


          <persistence:entity-manager-factory name="open18EntityManagerFactory" persistence-unit-name="open18" />
          
          <persistence:managed-persistence-context name="entityManager" auto-create="true"
            persistence-unit-jndi-name="#{open18EntityManagerFactory}"/>



          Here's what you should have:


          <persistence:entity-manager-factory name="open18EntityManagerFactory" persistence-unit-name="open18" />
          
          <persistence:managed-persistence-context name="entityManager" auto-create="true"
            entity-manager-factory="#{open18EntityManagerFactory}"/>



          However, a better approach is to have GlassFish load the persistence unit and then pull the EntityManagerFactory out of JNDI, like I suggest in chapter 9. First, you need a persistence unit ref in web.xml:


          <persistence-unit-ref>
              <persistence-unit-ref-name>open18/pu</persistence-unit-ref-name>
              <persistence-unit-name>open18</persistence-unit-name>
          </persistence-unit-ref>



          Then your persistence configuration in Seam is reduced to a single component, where you will now properly use the persistence-unit-jndi-name attribute:


          <persistence:managed-persistence-context name = "entityManager" auto-create="true"
            persistence-unit-jndi-name="java:comp/env/open18/pu"/>

          • 2. Re: Problems configuring Seam 2.1.x with Glassfish+Derby
            Dan Allen Master

            By the way, I just added support for GlassFish in the seam-gen build. You should definitely give it a try. Please checkout the latest SVN.