WARN: HHH000277: Could not bind factory to JNDI

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WARN: HHH000277: Could not bind factory to JNDI相关的知识,希望对你有一定的参考价值。

WARN: HHH000277: Could not bind factory to JNDI
org.hibernate.engine.jndi.JndiException: Error parsing JNDI name [foo]
at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:141)
at org.hibernate.engine.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:157)
at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:103)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:497)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
at com.taray.view.TestMain.main(TestMain.java:24)
Caused by: 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.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:135)
... 6 more

一个警告,错误原因hibernate.cfg.xml下面<session-factory name="foo">要去掉name属性:

<?xml version=‘1.0‘ encoding=‘utf-8‘?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="foo">
        <!-- hibernate设计者给了我们常用的配置,其实要改数据库就改这儿就好了! -->
        <!-- property中的connection.*必须是点出来的,否则报错 -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.username">SCOTT</property>
        <property name="connection.password">Admin</property>
        <property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:orcl</property>
        <!-- 配置dialect方言 明确告诉hibernate我现在连接的哪个数据库 -->
         <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
         <mapping resource="com/taray/domain/Users.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

 

以上是关于WARN: HHH000277: Could not bind factory to JNDI的主要内容,如果未能解决你的问题,请参考以下文章

关于控制台输出 警告 log4j:WARN No appenders could be found for logger

crawlerlog4j:WARN No appenders could be found for logger (dao.hsqlmanager).

log4j:WARN No appenders could be found for logger

使用hibernate出现log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Versio

log4j:WARN No appenders could be found for logger

log4j:WARN No appenders could be found for logger 解决办法