在进行HIBERNATE调试的时候,出现问题!请赐教!!! 为什么找不到HEBERNATE的类???------------------------------------你的类导入到lib文件夹下面没有? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 hibernate包要放在WEB-INF/lib下实在不行重起试试 NoClassDefFoundErrorHibernate 的配置文件设置好了吗? 你要把那些生成的类*。hbm.xml放到hibernate的配置文件里面去 以上各位说的我都作了!我用的是eclipse+myeclipse! 是否有对应的pojo 和相应的 .hbm.xml 文件,是否在 hibernate的配置文件中引入了!注:.xml格式的配置文件可以直接引入, .properties格式的配置文件需要通过程序来引入, <?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. --><hibernate-configuration> <session-factory> <property name="connection.username">root</property> <property name="connection.url">jdbc:mysql://localhost:3306/customer</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="myeclipse.connection.profile">Customers_mysql</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <mapping resource="com/hibernate/dao/Customers.hbm.xml" />----我在这里已经引入了! </session-factory></hibernate-configuration> com.studytest.struts.action.AddUserAction.execute(AddUserAction.java:56)看看你这一行写得什么 这一行写的是: usehibernate.saveCustomers(customers);saveCustomers(customers)方法是:public void saveCustomers(Customers customers)throws Exception{ Session session = SessionFactory.currentSession(); Transaction tx = null; try{ tx = session.beginTransaction(); session.save(customers); tx.commit(); } catch(Exception e){ if(tx != null){ tx.rollback(); } throw e; } finally{ SessionFactory.closeSession(); }}SessionFactory中的currentSession():public static Session currentSession() throws HibernateException { Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) { if (sessionFactory == null) { try { cfg.configure(CONFIG_FILE_LOCATION); sessionFactory = cfg.buildSessionFactory(); } catch (Exception e) { e.printStackTrace(); } } session = (sessionFactory != null) ? sessionFactory.openSession() : null; threadLocal.set(session); }return session;} Java反射,Int和Integet类型设置不成功,String可以设置 java 核心技术里面的问题 好心人解答 servlet急 谈谈struts2拦截器与spring的aop 关于struts获取按钮的值的问题 有谁实现过流媒体吗? 关于hibernate的语句like查询,高手来 img标签的src属性等于servlet名,求详细的解释 Hibernate单向一对多怎么自定义中间表 http://localhost:端口 这样居然可以访问项目? structs 中怎么做一个forward可以指向其他网站,比如www.csdn.net? 我用Sring连接数据库时报这样错
实在不行重起试试
我用的是eclipse+myeclipse!
是否在 hibernate的配置文件中引入了!
注:.xml格式的配置文件可以直接引入,
.properties格式的配置文件需要通过程序来引入,
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration> <session-factory>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/customer</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="myeclipse.connection.profile">Customers_mysql</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<mapping resource="com/hibernate/dao/Customers.hbm.xml" />----我在这里已经引入了! </session-factory></hibernate-configuration>
usehibernate.saveCustomers(customers);saveCustomers(customers)方法是:
public void saveCustomers(Customers customers)throws Exception{ Session session = SessionFactory.currentSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
session.save(customers);
tx.commit();
}
catch(Exception e){
if(tx != null){
tx.rollback();
}
throw e;
}
finally{
SessionFactory.closeSession();
}
}SessionFactory中的currentSession():public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}return session;
}