初学 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 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 有关系。
特此记录。
Hibernate 异常 : Error parsing JNDI name [xxx],布布扣,bubuko.com
时间: 2024-10-22 16:05:48