首页 > 代码库 > Hibernate 异常 : Error parsing JNDI name [xxx]
Hibernate 异常 : Error parsing JNDI name [xxx]
初学 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 : org.hibernate.internal.SessionFactoryRegistry@1a1ecd 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 JNDI 21:16:36,066 WARN SessionFactoryRegistry:116 - HHH000277: Could not bind factory to JNDI org.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个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。