6 Replies Latest reply on Apr 25, 2008 8:52 PM by metal610

    EntityManager is null

    metal610

      Hi all,


      My EntityManager is null, and I'm pretty sure that I don't have something set right in my configurations. I'm trying to use hibernate as my context. I followed the reference pdf, but I still can't get it. Any help would be much appreciated.


      Below are my components.xml, datasource, and hibernate.cfg.xml. If there is anything else that is needed, just say so and I'll post it.


      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:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                  "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                  http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                  http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                  http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                  http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                  http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                  http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                  http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
      http://jboss.com/products/seam/navigation http://jboss.com/products/seam/navigation-2.1.xsd">
          
          <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
          
          <core:manager concurrent-request-timeout="500" 
                        conversation-timeout="120000" 
                        conversation-id-parameter="cid"
                        parent-conversation-id-parameter="pid"/>
          
          <transaction:ejb-transaction />
          
          <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
          
          <persistence:managed-hibernate-session name="registrationDatabase" auto-create="true" session-factory-jndi-name="java:/registrationDatabase"/>
          
          <factory name="session" 
               scope="STATELESS" 
               auto-create="true" 
               value="#{entityManager.delegate}"/>
      
      </components>
      


      datasource


      <?xml version="1.0" encoding="UTF-8"?>
      
      <!DOCTYPE datasources
          PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
          "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
          
      <datasources>
         
         <local-tx-datasource>
            <jndi-name>testDatasource</jndi-name>
            <connection-url>jdbc:postgresql://localhost/registrationpage</connection-url>
            <driver-class>org.postgresql.Driver</driver-class>
            <user-name>username</user-name>
            <password>password</password>
         </local-tx-datasource>
          
      </datasources>



      hibernate.cfg.xml


      <!DOCTYPE hibernate-configuration PUBLIC
         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      
      <hibernate-configuration>
          <session-factory name="java:/registrationDatabase">
              <property name="show_sql">false</property>
              <property name="connection.datasource">java:/testDatasource</property>
              <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
              <property name="transaction.flush_before_completion">true</property>
              <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
              <mappings...../>
          </session-factory>
      </hibernate-configuration>


        • 1. Re: EntityManager is null
          nickarls

          You define a shortcut to the entityManager.delegate but you are missing the entityManager definition itself?

          • 2. Re: EntityManager is null
            metal610

            That was not supposed to be there. I had that there from when I was trying to use an EntityManager. By doing that, are you able to inject an EntityManager into your code? If so, then how can I do that for my hibernate Session?

            • 3. Re: EntityManager is null
              pmuir

              Read this

              • 4. Re: EntityManager is null
                mcarrizo

                Excuse me, but I dont really understand. I'm changing my app from ejb3 to hibernate context, and I'm having the same issue. I just need a boolean answer. With hibernate boostrapping, should i have an EntityManager defined or not ?

                • 5. Re: EntityManager is null
                  mcarrizo

                  Hi. Im having the same issue and I dont really understand what to do. Im trying to use entity-querys, and the app. is throwing the same exception. Thanks.

                  • 6. Re: EntityManager is null
                    metal610

                    No, you shouldn't have an entity manager defined. If all you want is Hibernate, then all you need in your components.xml is three lines:


                    <persistence:hibernate-session-factory name="sessionFactory"/>
                        
                    <persistence:managed-hibernate-session name="hibSession" auto-create="true" session-factory="#{sessionFactory}"/>
                        
                    <transaction:hibernate-transaction session="#{hibSession}"/>
                    



                    With those three lines, all of the hibernate stuff should work just fine. The only other thing that could mess things up is if your data source is wrong or your hibernate.cfg.xml is wrong.