0 Replies Latest reply on Nov 29, 2004 5:47 AM by rajs1

    Hibernate2 with JBoss4 (cannot bind) ?

    rajs1

      I don't know if this is the correct forum for this post but there seems to be nothing dedicated to Hibernate with JBoss4 at the moment.

      I am trying a simple test with Hibernate on JBoss 4 (with Firebird as the DB) but cannot get a context.lookup to work.

      I have replaced the jboss-hibernate.jar file with the one mentioned in the "http://www.jboss.org/wiki/Wiki.jsp?page=JBossHibernate" and renamed it (from: jboss-hibernate-NEW.jar) to jboss-hibernate.jar

      I have deployed the har file with the following structure:

      test.har:
      meta-inf/hibernate-service.xml
      com/test/myclasses
      com/test/mymapping.hbm.xml

      The hibernate-service.xml is

      <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.har:service=Hibernate">
       <attribute name="DatasourceName">java:/DefaultDS</attribute>
       <attribute name="SessionFactoryName">java:/hibernate/SessionFactory</attribute>
       <attribute name="Dialect">net.sf.hibernate.dialect.FirebirdDialect</attribute>
       <attribute name="CacheProviderClass">net.sf.hibernate.cache.HashtableCacheProvider</attribute>
      </mbean>
      



      The jboss output is as follows:
      ...
       [StandardService] Starting service jboss.web
       [StandardEngine] Starting Servlet Engine: Apache Tomcat/5.0.28
       [StandardHost] XML validation disabled
       [Catalina] Server startup in 62 ms
       [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=file:/D:/jboss-4.0.0RC2/server/default/deploy/http-invoker.sar/invoker.war/
       [TomcatDeployer] deploy, ctxPath=/ws4ee, warUrl=file:/D:/jboss-4.0.0RC2/server/default/tmp/deploy/tmp10181jboss-ws4ee-exp.war/
       [TomcatDeployer] deploy, ctxPath=/, warUrl=file:/D:/jboss-4.0.0RC2/server/default/deploy/jbossweb-tomcat50.sar/ROOT.war/
       [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=file:/D:/jboss-4.0.0RC2/server/default/deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/
       [ConnectionFactoryBindingService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=DefaultDS,service=ConnectionFactoryBinding to JNDI name 'java:DefaultDS'
       [ConnectionFactoryBindingService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=JmsXA,service=ConnectionFactoryBinding to JNDI name 'java:JmsXA'
       [MailService] Mail Service bound to java:/Mail
       [Environment] Hibernate 2.1.5
       [Environment] hibernate.properties not found
       [Environment] using CGLIB reflection optimizer
       [Configuration] Searching for mapping documents in jar: test.har
       [Configuration] Found mapping documents in jar: com/test/Person.hbm.xml
       [Binder] Mapping class: com.test.Person -> Cnt_Person
       [Configuration] processing one-to-many association mappings
       [Configuration] processing one-to-one association property references
       [Configuration] processing foreign key constraints
       [Dialect] Using dialect: net.sf.hibernate.dialect.FirebirdDialect
       [SettingsFactory] Use outer join fetching: true
       [NamingHelper] JNDI InitialContext properties:{}
       [DatasourceConnectionProvider] Using datasource: java:/DefaultDS
       [TransactionFactoryFactory] Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
       [NamingHelper] JNDI InitialContext properties:{}
       [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
       [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
       [NamingHelper] JNDI InitialContext properties:{}
       [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
       [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
       [SettingsFactory] Use scrollable result sets: true
       [SettingsFactory] Use JDBC3 getGeneratedKeys(): false
       [SettingsFactory] Optimize cache for minimal puts: false
       [SettingsFactory] Query language substitutions: {}
       [SettingsFactory] cache provider: net.sf.hibernate.cache.HashtableCacheProvider
       [Configuration] instantiating and configuring caches
       [SessionFactoryImpl] building session factory
       [SessionFactoryObjectFactory] Factory name: java:/hibernate/SessionFactory
       [NamingHelper] JNDI InitialContext properties:{}
       [NamingHelper] Creating subcontext: hibernate
       [SessionFactoryObjectFactory] Bound factory to JNDI name: java:/hibernate/SessionFactory
       [SessionFactoryObjectFactory] InitialContext did not implement EventContext
       [NamingHelper] JNDI InitialContext properties:{}
       [EjbModule] Deploying MEJB
       [EJBDeployer] Deployed: file:/D:/jboss-4.0.0RC2/server/default/deploy/management/ejb-management.jar
       [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=file:/D:/jboss-4.0.0RC2/server/default/deploy/jmx-console.war/
       [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=file:/D:/jboss-4.0.0RC2/server/default/tmp/deploy/tmp10233web-console-exp.war/
      ...
      



      I can see this line:
      [SessionFactoryObjectFactory] Bound factory to JNDI name: java:/hibernate/SessionFactory

      But when I run this:

       Context context = null;
       SessionFactory fac = null;
       try
       {
       env = new Hashtable();
       env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       env.put(Context.PROVIDER_URL, "localhost:1099");
       env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
       context = new InitialContext(env);
       fac = (SessionFactory)context.lookup("java:/hibernate/SessionFactory");
      ...
      



      I get:

      javax.naming.NameNotFoundException: hibernate not bound
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
       at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
       at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
       at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:529)
       at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:508)
       at javax.naming.InitialContext.lookup(InitialContext.java:347)
       at connection.TestJBossConnection.testConnection(TestJBossConnection.java:33)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
      



      If I run this:

      HibernateContext.getSession("java:/hibernate/SessionFactory");
      



      I get:
      java.lang.ExceptionInInitializerError
       at connection.TestJBossConnection.testConnection(TestJBossConnection.java:37)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
      Caused by: java.lang.IllegalStateException: An error occured while looking up the transaction manager: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
       at org.jboss.tm.TransactionLocal.<init>(TransactionLocal.java:57)
       at org.jboss.hibernate.session.HibernateContext$1.<init>(HibernateContext.java:40)
       at org.jboss.hibernate.session.HibernateContext.<clinit>(HibernateContext.java:38)
      




      Documentation on using Hibernate with JBoss seems to be very thin on the ground. Most of the Hibernate links in the JBoss website redirect to the Hibernate site.

      All the hibernate docs seem to talk about using Hibernate with Tomcat (which works without any problems).

      Cheers
      -raj