Hibernate 異常 : Error parsing JNDI name [xxx]

來源:互聯網
上載者:User

標籤:hibernate   異常   jndi   


初學 Hibernate ,用官方給的日誌模板配置好了日誌,跑起小例子,

控制台中的日誌裡寫了一些異常:

21:16:36,036 DEBUG EntityLoader:146 - Static select for entity cn.sjll.hibernate435.model.UserModel [OPTIMISTIC_FORCE_INCREMENT]: select usermodel0_.ID as ID1_0_0_, usermodel0_.NAME as NAME2_0_0_, usermodel0_.AGE as AGE3_0_0_, usermodel0_.SEX as SEX4_0_0_ from USERS usermodel0_ where usermodel0_.ID=?21:16:36,056 DEBUG Loader:56 - Static select for action ACTION_MERGE on entity cn.sjll.hibernate435.model.UserModel: select usermodel0_.ID as ID1_0_0_, usermodel0_.NAME as NAME2_0_0_, usermodel0_.AGE as AGE3_0_0_, usermodel0_.SEX as SEX4_0_0_ from USERS usermodel0_ where usermodel0_.ID=?21:16:36,056 DEBUG Loader:56 - Static select for action ACTION_REFRESH on entity cn.sjll.hibernate435.model.UserModel: select usermodel0_.ID as ID1_0_0_, usermodel0_.NAME as NAME2_0_0_, usermodel0_.AGE as AGE3_0_0_, usermodel0_.SEX as SEX4_0_0_ from USERS usermodel0_ where usermodel0_.ID=?21:16:36,056 DEBUG SessionFactoryRegistry:67 - Initializing SessionFactoryRegistry : [email protected]21:16:36,066 DEBUG SessionFactoryRegistry:89 - Registering SessionFactory: 79e91a19-1980-411c-b450-bc0bb5f3abe0 ()21:16:36,066 DEBUG SessionFactoryRegistry:100 - Attempting to bind SessionFactory [] to JNDI21:16:36,066  WARN SessionFactoryRegistry:116 - HHH000277: Could not bind factory to JNDIorg.hibernate.engine.jndi.JndiException: Error parsing JNDI name []    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:1857)    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)    at cn.sjll.hibernate435.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:11)    at cn.sjll.hibernate435.util.HibernateUtil.<clinit>(HibernateUtil.java:7)    at cn.sjll.hibernate435.util.TestCRUD.main(TestCRUD.java:15)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:662)    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)    at javax.naming.InitialContext.getNameParser(InitialContext.java:499)    at org.hibernate.engine.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:135)    ... 8 more


後來發現我的 hibernate.cfg.xml 中的 session-factory name="",

<hibernate-configuration>    <session-factory name="">

去掉 name="",再跑起來,日誌就不報上面的資訊,寫上 name="sf" 或者別的,但不配置 JNDI,同樣會報上述資訊,看來 session-factory 可選屬性中,如果寫上 name 就 和 JNDI 有關係。


特此記錄。

本文出自 “菜鳥笨飛” 部落格,請務必保留此出處http://srteert.blog.51cto.com/4009782/1416439

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.