把mysql的驱动换一下
org.gjt.mm.mysql.Driver<mapping resource="org/bromon/zizz/pojo/UserInfo.hbm" />
写成
<mapping resource="org/bromon/zizz/pojo/UserInfo.hbm.xml" />用jsp测试一下数据库能否连上
org.gjt.mm.mysql.Driver<mapping resource="org/bromon/zizz/pojo/UserInfo.hbm" />
写成
<mapping resource="org/bromon/zizz/pojo/UserInfo.hbm.xml" />用jsp测试一下数据库能否连上
<hibernate-mapping package="org.bromon.zizz.pojo">
看看这个目录下是否有UserInfo.class文件
因为错误提示说ClassNotFoundException UserInfo看看classes目录下是否拷入了log4j.properties
因为log4j.jar这个包需要log4j.properties是否加入了
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;public class HibernateUtil { private static Log log = LogFactory.getLog(HibernateUtil.class); private static final SessionFactory sessionFactory; static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
} public static final ThreadLocal session = new ThreadLocal(); public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
} public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
}最后按这个看看如何
http://www.hibernate.org/hib_docs/reference/zh-cn/html_single/
log4j:WARN Please initialize the log4j system properly.
net.sf.hibernate.MappingException: Error reading resource: org/bromon/zizz/pojo/UserInfo.hbm少log4j.properties 文件!!
net.sf.hibernate.MappingException: Error reading resource: org/bromon/zizz/pojo/UserInfo.hbm
hibernate下面的配置文件命名应该是UserInfo.hbm.xml,在hibernate.cfg.xml中改为
<mapping resource="org/bromon/zizz/pojo/hibernate.cfg.xml" />
<class name="UserInfo" table="user_info">改为
<hibernate-mapping >
<class name="org.bromon.zizz.pojo.erInfo" table="user_info">这可能是eclipse的一个bug
插件帮你生成的hibernate.cfg.xml的格式如下
<property name="hibernate.connection.url">
jdbc:mysql://localhost/loguser
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>但你一定要修改为
<property name="hibernate.connection.url">jdbc:mysql://localhost/loguser</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>才能成功!!(都要改成这样) 这个大bug让我郁闷了一下午,到现在还有些晕!!这种情况的出错信息一般说驱动找不到,但你清楚你的驱动是放对位置的!!!
说得可以试试