1 Reply Latest reply on May 9, 2006 2:47 AM by Maarten Roosendaal

    JNDI lookup is null?

    Nancy Aggarwal Newbie

      hi,

      I want to configure Hibernate to Jboss using JNDI.

      I hv created a hibernate-service.xml and placed in deploy directory.



      Hibernate-service.xml::::::::::::::::::





      jdbc/sqlserver org.hibernate.dialect.SQLServerDialect hibernate/SessionFactory





      Log on Jboss console:::::::::::::::::::::::::



      17:45:19,000 INFO [NamingHelper] JNDI InitialContext properties:{}

      17:45:19,093 INFO [DatasourceConnectionProvider] Using datasource: jdbc/sqlserver

      17:45:19,203 INFO [SettingsFactory] RDBMS: Microsoft SQL Server, version: Microsoft SQL Server 2000 - 8.00.194 (Intel X86)

      Aug 6 2000 00:57:48

      Copyright (c) 1988-2000 Microsoft Corporation

      Enterprise Evaluation Edition on Windows NT 5.0 (Build 2195: Service Pack 4)



      17:45:19,218 INFO [SettingsFactory] JDBC driver: SQLServer, version: 2.2.0040

      17:45:19,234 INFO [Dialect] Using dialect: org.hibernate.dialect.SQLServerDialect

      17:45:19,234 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory

      17:45:19,234 INFO [NamingHelper] JNDI InitialContext properties:{}

      17:45:19,234 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup

      17:45:19,250 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup

      17:45:19,250 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup

      17:45:19,250 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup

      17:45:19,250 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled

      17:45:19,250 INFO [SettingsFactory] Automatic session close at end of transaction: enabled

      17:45:19,250 INFO [SettingsFactory] Scrollable result sets: enabled

      17:45:19,265 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): disabled

      17:45:19,265 INFO [SettingsFactory] Connection release mode: after_statement

      17:45:19,281 INFO [SettingsFactory] Default batch fetch size: 1

      17:45:19,281 INFO [SettingsFactory] Generate SQL with comments: disabled

      17:45:19,281 INFO [SettingsFactory] Order SQL updates by primary key: disabled

      17:45:19,312 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory

      17:45:19,312 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory

      17:45:19,312 INFO [SettingsFactory] Query language substitutions: {}

      17:45:19,328 INFO [SettingsFactory] Second-level cache: enabled

      17:45:19,328 INFO [SettingsFactory] Query cache: disabled

      17:45:19,328 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider

      17:45:19,328 INFO [SettingsFactory] Optimize cache for minimal puts: disabled

      17:45:19,328 INFO [SettingsFactory] Structured second-level cache entries: disabled

      17:45:19,328 INFO [SettingsFactory] Statistics: disabled

      17:45:19,328 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled

      17:45:19,328 INFO [SettingsFactory] Default entity-mode: pojo

      17:45:19,390 INFO [SessionFactoryImpl] building session factory

      17:45:19,406 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured

      17:45:19,406 INFO [NamingHelper] JNDI InitialContext properties:{}

      17:45:19,406 INFO [Hibernate] SessionFactory successfully built and bound into JNDI [hibernate/SessionFactory]





      This means hibernate is bound into JNDI.



      Now I want to lookup the hibernate sessionfactory using JNDI



      Code to look up::::::::::::::::::::

      InitialContext initialContext = null;

      Hashtable environment = new Hashtable();

      environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

      environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

      environment.put(Context.PROVIDER_URL, "jnp://localhost:1099");

      try {

      initialContext = new InitialContext(environment);

      } catch (NamingException e) {

      // TODO Auto-generated catch block

      e.printStackTrace();

      }

      String jndiName = "java:hibernate/SessionFactory";

      Object obj=ctx.lookup(jndiName);

      System.out.println("obj"+obj);





      Output is null?Why?
      Thanks