错误1:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
解决方法:
复制 hibernate-3.2/etc/log4j.properties 文件放到web-inf/class目录下面,在eclipse里面放到src目录下面,会自动拷贝到class目录下面去。
错误2(报错,但是可以正常运行):
00:12:55,171 WARN SessionFactoryObjectFactory:98 - Could not bind factory to JNDI
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.util.NamingHelper.bind(NamingHelper.java:52)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:306)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at org.javawind.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:12)
at org.javawind.hibernate.DataDAO.getAll(DataDAO.java:64)
at org.javawind.beans.PageIndex.main(PageIndex.java:19)
解决方法:
在hibernate.cfg.xml中session-factory设置了name属性,hibernate会试图把这个sessionfacotry注册到jndi中去,将<session-factory name="***"> 的 name属性去掉即可解决