These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Exception while building sessionFactory
PostPosted: Wed Sep 03, 2008 2:50 pm 
Newbie

Joined: Wed Sep 03, 2008 2:40 pm
Posts: 1
Hibernate version:3.2.6

The cfg file looks like this
<hibernate-configuration>
<session-factory name="xxxdb">
<property name="hibernate.connection.provider_class">xxx.ism.core.hibernate.XXXConnectionProvider</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>


Problem

We are running our application in a non-managed environment, therefore we are not using JNDI.
In order to get a connection, we are using a custom connection provider which provides a connection object from an existing connection pool.

Our application runs fine. We are able to execute queries and get the result. However we noticed that during the process of building the session factory, we get the exception given below. Despite this the application runs without a problem. If we do not provide a name for the session factory, we do not get this exception.
(<session-factory> ...... </session-factory> )
Does this mean that providing a name to a session factory is possible only while using JNDI? We would like to provide a name to the session factory as we will be connecting to multiple databases in our application. How do we go about resolving this issue? Thanks in advance.


Full stack trace of any exception that occurs:

We get the following exception -
2008-09-03 11:21:53,250 DEBUG [main] (SessionFactoryObjectFactory.java:39) - initializing class SessionFactoryObjectFactory
2008-09-03 11:21:53,250 DEBUG [main] (SessionFactoryObjectFactory.java:76) - registered: 2bc66f711c2972f7011c2972fac20000 (emandb)
2008-09-03 11:21:53,250 INFO [main] (SessionFactoryObjectFactory.java:86) - Factory name: xxxdb
2008-09-03 11:21:53,250 INFO [main] (NamingHelper.java:26) - JNDI InitialContext properties:{}
2008-09-03 11:21:53,265 DEBUG [main] (NamingHelper.java:48) - binding: xxxdb
2008-09-03 11:21:53,265 WARN [main] (SessionFactoryObjectFactory.java:98) - Could not bind factory to JNDI
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 javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at eman.ism.core.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:47)
at eman.ism.eue.db.service.BaseDBService.startOperation(BaseDBService.java:44)
at eman.ism.eue.db.service.TestDBService.get15MinsTestTrend(TestDBService.java:46)
at eman.ism.eue.db.service.TestDBServiceTest.testGet15MinsTestTrend(TestDBServiceTest.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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 org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
2008-09-03 11:21:53,265 DEBUG [main] (SessionFactoryImpl.java:308) - instantiated session factory


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2008 11:03 pm 
Beginner
Beginner

Joined: Wed Apr 20, 2005 9:30 am
Posts: 39
Actually, what it means is that the session factory name only has relevance in JNDI. If you are connecting to multiple databases, you'll either have multiple session factories OR be using Shards.

Either way, you can name things programatically - that JNDI name can't be referenced after the session factory is created unless you are retrieving the reference from JNDI. Best to just use variable naming for your multiple sessionFactories:

SessionFactory db_host1 = etc.
SessionFactory db_host2 = blahblah

Each will require its own configuration, mapping etc. You could of course, make a simple implementation of JNDI - it's just a hashmap and use that. That was the solution we used... made it real easy to port to a web application.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.