1 2 Previous Next 15 Replies Latest reply on Mar 13, 2007 1:40 PM by Michael Harrison

    What's wrong with this components.xml / persistence.xml pair

    Michael Harrison Newbie

      Hey everyone,

      I'm having trouble getting my Seam app to run on Tomcat; the entityManager is not being injected into my Seam objects, most notably the EntityQuery objects. [Note: This app works fine on JBoss, so this is a config issue.]

      Here is my components.xml file:

      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:framework="http://jboss.com/products/seam/framework"
       xsi:schemaLocation=
       "http://jboss.com/products/seam/core
       http://jboss.com/products/seam/core-1.1.xsd
       http://jboss.com/products/seam/components
      http://jboss.com/products/seam/components-1.1.xsd">
      
       <core:init jndi-pattern="#{ejbName}/local" debug="true"/>
      
       <core:microcontainer installed="true"/>
      
       <core:manager conversation-timeout="120000"/>
      
       <core:ejb installed="true"/>
      </components>


      And here is my persistence.xml file:
      <persistence>
       <persistence-unit name="omega">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/omegaDatasource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
       <property name="hibernate.hbm2ddl.auto" value="none"/>
       </properties>
       </persistence-unit>
      </persistence>


      Thank you sincerely,
      -Michael

        • 1. Re: What's wrong with this components.xml / persistence.xml
          Fernando Montaño Expert

          It seems you need the next line in you components.xml

           <core:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/omegaDatasource"/>
          


          HTH.

          • 2. Re: What's wrong with this components.xml / persistence.xml
            Michael Harrison Newbie

            Thank you so much for your response. At least now I'm getting different error messages. :-)

            There seems to be some conflicts in the Seam documentation. Do you need a "entity-manager-factory" node as well? In some places I've read where this configuration is needed (even though it never works for me):

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


            In Seam 1.2, which is the correct way to create the entityManager component when deploying to Tomcat?

            All the best,
            -Michael

            • 3. Re: What's wrong with this components.xml / persistence.xml
              Michael Harrison Newbie

              BTW, I wasn't being sarcastic. I was ramming against the "null entityManager" error for quite some time, and your recommended config line has definitely pushed me closer to the finish line. Again, thank you.

              -Michael

              • 4. Re: What's wrong with this components.xml / persistence.xml
                Stuart Robertson Novice

                 

                "mlh496" wrote:
                Thank you so much for your response. At least now I'm getting different error messages. :-)

                There seems to be some conflicts in the Seam documentation. Do you need a "entity-manager-factory" node as well? In some places I've read where this configuration is needed (even though it never works for me):

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


                In Seam 1.2, which is the correct way to create the entityManager component when deploying to Tomcat?

                All the best,
                -Michael


                I'm using the EntityQuery successfully, and in my components.xml I have

                 <core:managed-persistence-context name="entityManager" auto-create="true"
                 persistence-unit-jndi-name="java:/fbEntityManagerFactory" />
                


                All of the Seam framework components (EntityController, Homes and Queries expect to find persistence-context named entityManger, though you can override these (look at the source, there's a getPersistenceContextName() method in each).

                What exceptions are you seeing?

                • 5. Re: What's wrong with this components.xml / persistence.xml
                  Fernando Montaño Expert

                  Ok, I will describe what I have in my configuration files when I deploy to Tomcat.

                  1.- My components.xml

                  
                   <core:managed-persistence-context name="entityManager" auto-create="true"
                   persistence-unit-jndi-name="java:/myappEntityManagerFactory"/>
                  


                  2.- My persistence.xml
                   <persistence-unit name="myappPU">
                   <provider>org.hibernate.ejb.HibernatePersistence</provider>
                   <jta-data-source>java:/myappDatasource</jta-data-source>
                   <properties>
                   <property name="hibernate.hbm2ddl.auto" value="update"/>
                   <property name="hibernate.cache.use_query_cache" value="true"/>
                   <property name="hibernate.show_sql" value="true"/>
                   <!-- These are the default for JBoss EJB3, but not for HEM: -->
                   <property name="jboss.entity.manager.factory.jndi.name" value="java:/myappEntityManagerFactory"/>
                   </properties>
                   </persistence-unit>
                  


                  3.- META-INF jboss-beans.xml
                  <bean name="myappDatasourceBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
                   <property name="driverClass">com.mysql.jdbc.Driver</property>
                   <property name="connectionURL">jdbc:mysql://192.168.10.1:3306/myapp</property>
                   <property name="userName"><value class="java.lang.String">fernando</value></property>
                   <property name="password"><value class="java.lang.String">fernando</value></property>
                   <property name="jndiName">java:/myappDatasource</property>
                   <property name="minSize">0</property>
                   <property name="maxSize">10</property>
                   <property name="blockingTimeout">1000</property>
                   <property name="idleTimeout">100000</property>
                   <property name="transactionManager"><inject bean="TransactionManager"/></property>
                   <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
                   <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
                   </bean>
                  
                   <bean name="myappDatasource" class="java.lang.Object">
                   <constructor factoryMethod="getDatasource">
                   <factory bean="myappDatasourceBootstrap"/>
                   </constructor>
                   </bean>
                  
                  




                  HTH.

                  • 6. Re: What's wrong with this components.xml / persistence.xml
                    Michael Harrison Newbie

                    I believe my jboss-beans.xml, persistence.xml and components.xml files are correct. I now receive the following error:

                    javax.faces.el.EvaluationException: Cannot get value for expression '#{usersList.firstResult}'
                     at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:402)
                    ...
                    ...
                    Caused by: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI
                     at org.jboss.seam.core.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:140)
                    ...
                    ...
                    
                    Caused by: javax.naming.NameNotFoundException: omegaDatasource not bound
                     at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
                    ...
                    ...


                    Here is my components.xml file:

                    <?xml version="1.0" encoding="UTF-8"?>
                    <components xmlns="http://jboss.com/products/seam/components"
                     xmlns:core="http://jboss.com/products/seam/core"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation=
                     "http://jboss.com/products/seam/core
                     http://jboss.com/products/seam/core-1.1.xsd
                     http://jboss.com/products/seam/components
                    http://jboss.com/products/seam/components-1.1.xsd">
                    
                     <core:init jndi-pattern="#{ejbName}/local" debug="true"/>
                    
                     <core:manager conversation-timeout="120000"/>
                    
                     <core:managed-persistence-context name="entityManager"
                     persistence-unit-jndi-name="java:/omegaDatasource"
                     auto-create="true"/>
                    
                    
                     <core:ejb installed="true"/>
                    
                    </components>


                    It seems that I do need to have an entity-manager-factory node for this to work on Tomcat. However, I have also noticed that if I take the 2 beans in my jboss-beans.xml file and put them in the embedded-jboss-beams.xml file, then I have fewer problems. However, according to the Seam documentation, this should not be necessary.

                    -Michael

                    • 7. Re: What's wrong with this components.xml / persistence.xml
                      Fernando Montaño Expert

                      You don't need to add application specific configuration to embedded-jboss-beans.xml. app/MET-INF/jboss-beans.xml are for that.

                      If you still have the problems, can we see your jboss-beans.xml and persistence.xml content?

                      • 8. Re: What's wrong with this components.xml / persistence.xml
                        Michael Harrison Newbie

                        Here is my persistence.xml file:

                        <persistence>
                         <persistence-unit name="omegaFactory">
                         <provider>org.hibernate.ejb.HibernatePersistence</provider>
                         <jta-data-source>java:/omegaDatasource</jta-data-source>
                         <properties>
                         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
                         <property name="hibernate.transaction.flush_before_completion" value="true"/>
                         <property name="hibernate.show_sql" value="true"/>
                         <property name="jboss.entity.manager.factory.jndi.name" value="java:/omegaDatasource"/>
                         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                         </properties>
                         </persistence-unit>
                        </persistence>


                        And here is my jboss-beans.xml file:

                        <?xml version="1.0" encoding="UTF-8"?>
                        
                        <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
                         xmlns="urn:jboss:bean-deployer:2.0">
                        
                         <bean name="omegaDatasourceBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
                         <property name="driverClass">com.mysql.jdbc.Driver</property>
                         <property name="connectionURL">jdbc:mysql://localhost:3306/omega</property>
                         <property name="userName"><value class="java.lang.String">username</value></property>
                         <property name="password"><value class="java.lang.String">password</value></property>
                         <property name="jndiName">java:/omegaDatasource</property>
                         <property name="minSize">0</property>
                         <property name="maxSize">10</property>
                         <property name="blockingTimeout">1000</property>
                         <property name="idleTimeout">100000</property>
                         <property name="transactionManager"><inject bean="TransactionManager"/></property>
                         <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
                         <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
                         </bean>
                        
                         <bean name="omegaDatasource" class="java.lang.Object">
                         <constructor factoryMethod="getDatasource">
                         <factory bean="omegaDatasourceBootstrap"/>
                         </constructor>
                         </bean>
                        </deployment>


                        When I turn logging to debug, this seems to be the error that starts it all:

                        Caused by: java.lang.NullPointerException
                         at org.jboss.seam.core.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:96)
                        


                        Thank you for taking a look at this,
                        -Michael

                        • 9. Re: What's wrong with this components.xml / persistence.xml
                          Fernando Montaño Expert

                          Maybe I'm wrong, but it could be because you have the same name for jta-data-source (java:/omegaDatasource) and also the same one for jboss.entity.manager.factory.jndi.name (java:/omegaDatasource).

                          Try changing the name of jboss.entity.manager.factory.jndi.name (persistence.xml) to java:/omegaEntityManagerFactory and then change the components.xml to use it, as follows:

                          <core:managed-persistence-context name="entityManager"
                           persistence-unit-jndi-name="java:/omegaEntityManagerFactory"
                           auto-create="true"/>
                          


                          • 10. Re: What's wrong with this components.xml / persistence.xml
                            Michael Harrison Newbie

                            It seems the entity manager is not getting inject into the right place. I continue to get this error:

                            Caused by: java.lang.NullPointerException
                             at org.jboss.seam.core.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:96)
                            


                            Here are my updated persistence.xml, components.xml and jboss-beans.xml files:

                            persistence.xml

                            <persistence>
                             <persistence-unit name="omegaFactory">
                             <provider>org.hibernate.ejb.HibernatePersistence</provider>
                             <jta-data-source>java:/omegaDatasource</jta-data-source>
                             <properties>
                             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
                             <property name="hibernate.transaction.flush_before_completion" value="true"/>
                             <property name="hibernate.show_sql" value="true"/>
                             <property name="jboss.entity.manager.factory.jndi.name" value="java:/omegaEntityDatasource"/>
                             <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
                             <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
                             </properties>
                             </persistence-unit>
                            </persistence>
                            


                            components.xml
                            <?xml version="1.0" encoding="UTF-8"?>
                            <components xmlns="http://jboss.com/products/seam/components"
                             xmlns:core="http://jboss.com/products/seam/core"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation=
                             "http://jboss.com/products/seam/core
                             http://jboss.com/products/seam/core-1.1.xsd
                             http://jboss.com/products/seam/components
                            http://jboss.com/products/seam/components-1.1.xsd">
                            
                             <core:init jndi-pattern="#{ejbName}/local" debug="true"/>
                            
                             <core:manager conversation-timeout="120000"/>
                            
                             <core:managed-persistence-context name="entityManager"
                             persistence-unit-jndi-name="java:/omegaEntityDatasource"
                             auto-create="true"/>
                            
                            
                             <core:ejb installed="true"/>
                            
                            </components>


                            jboss-beans.xml

                            <?xml version="1.0" encoding="UTF-8"?>
                            
                            <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
                             xmlns="urn:jboss:bean-deployer:2.0">
                            
                             <bean name="omegaDatasourceBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
                             <property name="driverClass">com.mysql.jdbc.Driver</property>
                             <property name="connectionURL">jdbc:mysql://localhost:3306/omega</property>
                             <property name="userName"><value class="java.lang.String">username</value></property>
                             <property name="password"><value class="java.lang.String">password</value></property>
                             <property name="jndiName">java:/omegaDatasource</property>
                             <property name="minSize">0</property>
                             <property name="maxSize">10</property>
                             <property name="blockingTimeout">1000</property>
                             <property name="idleTimeout">100000</property>
                             <property name="transactionManager"><inject bean="TransactionManager"/></property>
                             <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
                             <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
                             </bean>
                            
                             <bean name="omegaDatasource" class="java.lang.Object">
                             <constructor factoryMethod="getDatasource">
                             <factory bean="omegaDatasourceBootstrap"/>
                             </constructor>
                             </bean>
                            </deployment>
                            


                            Surely some permutation should work. :-)
                            -Michael

                            • 11. Re: What's wrong with this components.xml / persistence.xml
                              Michael Harrison Newbie

                              Looking through the log-file, I see this error:

                              16:14:20,044 INFO [Component] Component: entityManager, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.core.ManagedPersistenceContext
                              16:14:20,044 DEBUG [Component] entityManager.entityManagerFactory=omegaDatabase
                               16:14:20,060 ERROR [[/omega]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
                               java.lang.IllegalArgumentException: No converter for type: org.jboss.seam.core.Expressions$ValueBinding
                               at org.jboss.seam.util.Conversions.getConverter(Conversions.java:55)
                               at org.jboss.seam.Component$ConstantInitialValue.<init>(Component.java:1998)


                              This suggests that Seam is succeeding in making an entityManagerFactory instance, but cannot pass it to the SeamListener. How to fix this? I have no idea... Seam continues to tease me...

                              -Michael

                              • 12. Re: What's wrong with this components.xml / persistence.xml
                                Fernando Montaño Expert

                                I never seen an exception like that, I don't know the reason. But can I take a look to your complete log (since starting components up to final exception stack trace)?

                                • 13. Re: What's wrong with this components.xml / persistence.xml
                                  Michael Harrison Newbie

                                  I hope I'm not being too forward, but could you perhaps send me a WAR file that works for you on Tomcat 5.5? (Perhaps a simple app that has a single table in MySql.) My e-mail address is mlh496.register@gmail.com
                                  If I had a working MySql example on Tomcat 5.5, then I'm sure that I could identify where I am going wrong.

                                  Thank you again for your help. I've been stuck in configuration heck for 12 days now, and you've been most helpful.

                                  -Michael

                                  • 14. Re: What's wrong with this components.xml / persistence.xml
                                    Fernando Montaño Expert

                                    I have a sample running in tomcat (a simple one), I'll send you to the mail you provide me right away.

                                    1 2 Previous Next