0 Replies Latest reply on Jan 9, 2007 4:00 AM by Joachim Skeie

    Hibernate JNDI failure...

    Joachim Skeie Newbie

      Hello,

      I am trying to set up a web application that uses Spring and Hibernate on JBoss 4.0.5. The Hibernate classes are placed inside a .HAR inside the .EAR, and referenced in jboss-app.xml.

      I have placed jboss-service.xml inside the HAR:

      <?xml version="1.0" encoding="UTF-8"?>
      <server>
       <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
       <depends>jboss:service=Naming</depends>
       <attribute name="DatasourceName">java:/MyDS</attribute>
       <attribute name="Dialect">org.hibernate.dialect.OracleDialect</attribute>
       <attribute name="SessionFactoryName">java:hibernate/BMSessionFactory</attribute>
       <attribute name="CacheProviderClass">org.hibernate.cache.HashtableCacheProvider</attribute>
       <attribute name="ShowSqlEnabled">true</attribute>
       <attribute name="ScanForMappingsEnabled">true</attribute>
       </mbean>
      </server>
      


      and the following inside spring-web.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
      <beans>
       <bean id="mySessionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="java:hibernate/BMSessionFactory"/>
       </bean>
      
       <bean id="svinnDao" class="com.svinn.SvinnDao">
       <property name="sessionFactory"><ref local="mySessionFactory"/></property>
       </bean>
      
      </beans>
      


      When I deploy to JBoss, I get the following (important lines marked in bold):

      09:49:30,533 INFO [Configuration] Searching for mapping documents in jar: tmp28513bm.ear-1.0-SNAPSHOT.ear
      09:49:30,534 INFO [Configuration] Searching for mapping documents in jar: bm-hibernate.har
      09:49:30,534 INFO [Configuration] Searching for mapping documents in jar: bm.ejb-1.0-SNAPSHOT.jar
      09:49:30,536 INFO [NamingHelper] JNDI InitialContext properties:{}
      09:49:30,539 INFO [DatasourceConnectionProvider] Using datasource: java:/MyDS
      09:49:30,539 INFO [SettingsFactory] RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
      With the Partitioning, OLAP and Data Mining options
      09:49:30,539 INFO [SettingsFactory] JDBC driver: Oracle JDBC driver, version: 10.2.0.1.0
      09:49:30,540 INFO [Dialect] Using dialect: org.hibernate.dialect.OracleDialect
      09:49:30,542 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
      09:49:30,543 INFO [NamingHelper] JNDI InitialContext properties:{}
      09:49:30,543 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      09:49:30,543 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      09:49:30,543 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
      09:49:30,543 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
      09:49:30,543 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
      09:49:30,543 INFO [SettingsFactory] Automatic session close at end of transaction: enabled
      09:49:30,543 INFO [SettingsFactory] JDBC batch size: 15
      09:49:30,543 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
      09:49:30,544 INFO [SettingsFactory] Scrollable result sets: enabled
      09:49:30,544 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
      09:49:30,544 INFO [SettingsFactory] Connection release mode: after_statement
      09:49:30,544 INFO [SettingsFactory] Default batch fetch size: 1
      09:49:30,544 INFO [SettingsFactory] Generate SQL with comments: disabled
      09:49:30,544 INFO [SettingsFactory] Order SQL updates by primary key: disabled
      09:49:30,544 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      09:49:30,544 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      09:49:30,544 INFO [SettingsFactory] Query language substitutions: {}
      09:49:30,544 INFO [SettingsFactory] JPA-QL strict compliance: disabled
      09:49:30,544 INFO [SettingsFactory] Second-level cache: enabled
      09:49:30,544 INFO [SettingsFactory] Query cache: disabled
      09:49:30,544 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
      09:49:30,544 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
      09:49:30,545 INFO [SettingsFactory] Structured second-level cache entries: disabled
      09:49:30,545 INFO [SettingsFactory] Echoing all SQL to stdout
      09:49:30,545 INFO [SettingsFactory] Statistics: disabled
      09:49:30,545 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
      09:49:30,545 INFO [SettingsFactory] Default entity-mode: pojo
      09:49:30,549 INFO [SessionFactoryImpl] building session factory
      09:49:30,549 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
      09:49:30,549 INFO [NamingHelper] JNDI InitialContext properties:{}
      09:49:30,550 INFO [Hibernate] SessionFactory successfully built and bound into JNDI [java:hibernate/BMSessionFactory]
      


      Then, further down I get this Exception:

      09:49:31,102 ERROR [ContextLoader] Context initialization failed
       org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring-web.xml]: Initialization of bean failed; nested exception is javax.naming.NamingException: JNDI object with [java:hibernate/BMSessionFactory] not found: JNDI implementation returned null
       javax.naming.NamingException: JNDI object with [java:hibernate/BMSessionFactory] not found: JNDI implementation returned null
       at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:125)
       at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
       at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
       at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
      ...
      ...