-->
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.  [ 13 posts ] 
Author Message
 Post subject: Could not bind session factory to JNDI
PostPosted: Wed Nov 30, 2005 11:59 pm 
Beginner
Beginner

Joined: Tue Nov 01, 2005 5:21 am
Posts: 24
Hi,

When I create session factory using following statement:
sessionFactory = new Configuration().configure().buildSessionFactory();
it throws exceptions as following:

16:07:57,659 WARN SessionFactoryObjectFactory: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(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.getNameParser(InitialContext.java:429)
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:293)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)


Could anyone tell me what's wrong?

Thanks.

Yulei


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 12:53 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Check ur hibernate.cfg.xml or show it.

see to that you dont place name attribute in session-factory in your hibernate.cfg.xml.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject: Re: Could not bind session factory to JNDI
PostPosted: Thu Dec 01, 2005 1:07 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
chen_yulei wrote:
16:07:57,659 WARN SessionFactoryObjectFactory: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(NamingManager.java:640)
at


Exactly as it says. Refer to
http://www.hibernate.org/hib_docs/refer ... ional-jndi
for How-to configure Sessionfactory with a jndi name. If you specified a url for the SessionFactory to be bound to a Namespace, you need to specify the classname too. Pass in your InitialContextFactory implementation class to
hibernate.jndi.class.
For e.g.
hibernate.jndi.class=org.jnp.interfaces.NamingContextFactory (this is in the case of Jboss. use your app/web container's naming contextfactory).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 3:08 am 
Beginner
Beginner

Joined: Tue Nov 01, 2005 5:21 am
Posts: 24
what should I specify the property hibernate.session_factory_name if I use just JDK?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 4:25 am 
Beginner
Beginner

Joined: Tue Nov 01, 2005 5:21 am
Posts: 24
More information in detail:

I use JDK1.4.1, hibernate-3.1.

In hibernate.properties, I set:
hibernate.session_factory_name hibernate/session_factory

In hibernate.cfg.xml:
<session-factory name="java:hibernate/SessionFactory">

statement
sessionFactory = new Configuration().configure().buildSessionFactory();
throws exceptions as following:

building session factory
11:17:06,837 INFO SessionFactoryObjectFactory:86 - Factory name: java:hibernate/SessionFactory
11:17:06,847 INFO NamingHelper:26 - JNDI InitialContext properties:{}
11:17:07,368 WARN SessionFactoryObjectFactory: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(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.getNameParser(InitialContext.java:429)
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:293)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)

Could anyone tell me what's wrong? Please tell me how to set the property file and hibernate configure file.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 7:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
then don't give it a JNDI name


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 5:21 am 
Beginner
Beginner

Joined: Tue Nov 01, 2005 5:21 am
Posts: 24
steve wrote:
then don't give it a JNDI name


Could anyone tell me how? I comment the hibernate.session_factory_name property in the hibernate.properties file, but it does not help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 10:38 pm 
Beginner
Beginner

Joined: Tue Nov 01, 2005 5:21 am
Posts: 24
none help me? I urgently need help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 10:54 pm 
Beginner
Beginner

Joined: Tue Nov 01, 2005 5:21 am
Posts: 24
I solve it: do not supply session factory name in hibernate.cfg.xml.


Top
 Profile  
 
 Post subject: Re: Could not bind session factory to JNDI
PostPosted: Tue Dec 07, 2010 10:26 am 
Newbie

Joined: Thu Aug 19, 2010 1:25 pm
Posts: 3
Hi, i have exactly the same problem .. Here's my config file

Code:
<hibernate-configuration>
   <session-factory name="">
      <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="connection.url">jdbc:sqlserver:URL###</property>
      <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
      
      <property name="connection.username">NAME</property>
      <property name="connection.password">PASS</property>
   
      <property name="hibernate.default_schema">dbo</property>
      
      <mapping class="za.co.epsilon.domain.OverrideItemDo" />
      <mapping class="za.co.epsilon.domain.BatchOverrideDo" />
      <mapping class="za.co.epsilon.domain.TaskOverrideDo" />

   </session-factory>
</hibernate-configuration>

error
Code:
16:19:01,029  INFO NamingHelper:49 - JNDI InitialContext properties:{}
16:19:01,029  WARN SessionFactoryObjectFactory:121 - 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(NamingManager.java:645)
   at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
   at javax.naming.InitialContext.getNameParser(InitialContext.java:480)
   at org.hibernate.util.NamingHelper.bind(NamingHelper.java:75)
   at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:365)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
   at za.co.epsilon.factory.dao.HibernateUtil.configure(HibernateUtil.java:153)
   at za.co.epsilon.factory.dao.HibernateUtil.rebuildSessionFactory(HibernateUtil.java:135)
   at za.co.epsilon.factory.dao.HibernateUtil.getSessionFactory(HibernateUtil.java:105)
   at za.co.epsilon.test.BatchOverrideHibernateTest.getSession(BatchOverrideHibernateTest.java:22)
   at za.co.epsilon.test.BatchOverrideHibernateTest.init(BatchOverrideHibernateTest.java:47)
   at za.co.epsilon.test.BatchOverrideHibernateTest.main(BatchOverrideHibernateTest.java:34)
16:19:01,029  INFO BatchOverrideHibernateTest:58 - ---- Exception occurred : org.hibernate.HibernateException : No CurrentSessionContext configured!
org.hibernate.HibernateException: No CurrentSessionContext configured!
   at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:683)
   at za.co.epsilon.test.BatchOverrideHibernateTest.getSession(BatchOverrideHibernateTest.java:22)
   at za.co.epsilon.test.BatchOverrideHibernateTest.init(BatchOverrideHibernateTest.java:47)
   at za.co.epsilon.test.BatchOverrideHibernateTest.main(BatchOverrideHibernateTest.java:34)

hibernateUtil
Code:
    public static SessionFactory getSessionFactory() {
        String sfName = configuration.getProperty(Environment.SESSION_FACTORY_NAME);
        if ( sfName != null && !sfName.equals("")) {
            log.debug("Looking up SessionFactory in JNDI");
            try {
                return (SessionFactory) new InitialContext().lookup(sfName);
            } catch (NamingException ex) {
                throw new RuntimeException(ex);
            }
        } else if (sessionFactory == null) {
                 sessionFactory = new Configuration().configure().buildSessionFactory();
        }
        return sessionFactory;
    }


as you can see, "Environment.SESSION_FACTORY_NAME" does not exist on my hibernate config file...


Top
 Profile  
 
 Post subject: Re: Could not bind session factory to JNDI
PostPosted: Thu Dec 16, 2010 3:22 pm 
Newbie

Joined: Thu Dec 16, 2010 3:18 pm
Posts: 1
You need to remove the name attribute from your opening session factory tag in your hibernate configuration file so that it looks like the following:

<session-factory>


Top
 Profile  
 
 Post subject: Re: Could not bind session factory to JNDI
PostPosted: Mon Jan 03, 2011 3:48 am 
Newbie

Joined: Thu Aug 19, 2010 1:25 pm
Posts: 3
mmcvay wrote:
You need to remove the name attribute from your opening session factory tag in your hibernate configuration file so that it looks like the following:

<session-factory>

thanks mmcvay


Top
 Profile  
 
 Post subject: Re: Could not bind session factory to JNDI
PostPosted: Fri Jul 27, 2012 3:14 pm 
Newbie

Joined: Fri Jul 27, 2012 3:06 pm
Posts: 1
Check your hibernate.cfg.xml. If you have name attribute in session factory element then remove that. It should work

From:
<session-factory name="">
to:
<session-factory >

Hope this helps.

-Veydant

chen_yulei wrote:
Hi,

When I create session factory using following statement:
sessionFactory = new Configuration().configure().buildSessionFactory();
it throws exceptions as following:

16:07:57,659 WARN SessionFactoryObjectFactory: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(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.getNameParser(InitialContext.java:429)
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:293)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1145)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)


Could anyone tell me what's wrong?

Thanks.

Yulei


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.