[英]JndiException when using Hibernate 4.0 with Tomcat 7 and JSF 2.0
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 的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 的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 在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 : 您必须在hibernate.cfg.xml文件的“ java:”和“ comp”之间添加斜杠:
<property name="hibernate.connection.datasource">java:/comp/env/JSF_HIBER/ORACLE</property>
It will probably solve the issue 它可能会解决问题
You'll probably need the following in the META-INF/context.xml
to link your global JNDI resources to the application specific ones: 您可能需要在
META-INF/context.xml
执行以下操作,以将全局JNDI资源链接到特定于应用程序的资源:
<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
. 它将全局数据源
JSF_HIBER/ORACLE
链接到本地的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: 如果您不想创建应用程序级别的链接,则可以使用全局URL:
<property name="hibernate.connection.datasource">JSF_HIBER/ORACLE</property>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.