Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

After the application deploye, when method is execute , i am getting below error.

Caused by: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [java:comp/env/JSF_HIBER/ORACLE]
    at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
    at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:77)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
    at com.utils.HibernateUtils.<clinit>(HibernateUtils.java:19)
    ... 33 more
Caused by: javax.naming.NamingException: This context must be accessed through a java: URL
    at org.apache.naming.SelectorContext.parseName(SelectorContext.java:776)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:135)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
    ... 47 more

Context.xml

<Resource name="JSF_HIBER/ORACLE" auth="Container"
    type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000"
    username="****" password="**** driverClassName="oracle.jdbc.OracleDriver"
    url="jdbc:oracle:thin:@99.99.999.999:1521:xe" />

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.datasource">java:comp/env/JSF_HIBER/ORACLE</property>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="hibernate.connection.pool_size">10</property>
        <property name="show_sql">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
    <mapping class="com.entity.User"/>
    </session-factory>
</hibernate-configuration>

Web.xml

<resource-ref>
        <description>JSF_HIBER</description>
        <res-ref-name>JSF_HIBER/ORACLE</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

i don't know why i am getting this error, please help me...

You must add a slash between "java:" and "comp" in the hibernate.cfg.xml file :

<property name="hibernate.connection.datasource">java:/comp/env/JSF_HIBER/ORACLE</property>

It will probably solve the issue

Nicely done! You are a gentleman and a scholar. This fixed the problem for me. Strangely the old string works when you don't use Hibernate to obtain a javax.sql.DataSource. – Neil Oct 13, 2014 at 7:51

You'll probably need the following in the META-INF/context.xml to link your global JNDI resources to the application specific ones:

<Context>
  <ResourceLink name="JSF_HIBER/ORACLE"
            global="JSF_HIBER/ORACLE"
            type="javax.sql.DataSource"
</Context>

which links your global datasource JSF_HIBER/ORACLE to your local one java:comp/env/JSF_HIBER/ORACLE.

EDIT:

If you don't want to create an application level link, you can use the global url instead:

<property name="hibernate.connection.datasource">JSF_HIBER/ORACLE</property>
                I think problem is in my hibernet code.. pleses check it's corect or not..  try {  			Configuration conf = new Configuration(); 			conf.configure(); 			ServiceRegistry serviceRegistry = new ServiceRegistryBuilder() 					.applySettings(conf.getProperties()).buildServiceRegistry(); 			SESSION_FACTORY = conf.buildSessionFactory(serviceRegistry); 		} catch (Throwable ex) { 			throw new ExceptionInInitializerError(ex); 		}
– Jimit Tank
                Mar 14, 2013 at 14:49
                I did say add the code in your META-INF/context.xml not server.xml.  The error message points to a JNDI lookup that's not quite setup correctly.
– beny23
                Mar 14, 2013 at 14:52
                When i use globel url... <property name="hibernate.connection.datasource">JSF_HIBER/ORACLE</property> then i am getting below exception ::   Caused by: javax.naming.NameNotFoundException: Name JSF_HIBER is not bound in this Context 	at org.apache.naming.NamingContext.lookup(NamingContext.java:803) 	at org.apache.naming.NamingContext.lookup(NamingContext.java:145) 	at org.apache.naming.SelectorContext.lookup(SelectorContext.java:135)
– Jimit Tank
                Mar 15, 2013 at 7:22
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.