日期:2014-05-20  浏览次数:20833 次

hibernate类找不到的问题
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

public Blog getBlog(String userId) throws HibernateException {
  Session session = HibernateUtil.currentSession();
  Blog blog = null;
Transaction tx = null;
try {
tx = session.beginTransaction();

Query query = session.createQuery("from Blog where username=:userId");
query.setParameter("userId", userId);
List list = query.list();
if (!list.isEmpty())
blog = (Blog) list.get(0);
tx.commit();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
throw e;
}
session.close();
return blog;
}
}

提示
“找不到符号 符号:类HibernateException ”
“找不到符号 符号:类Session”
“找不到符号 符号:类Transaction ”

lib文件夹下已经添加了hibernate3.jar

------解决方案--------------------
lib文件夹下已经添加了hibernate3.jar

这个有啥用?这个不是在编译的时候使用的。你应该把它加入你的CLASSPATH

如果你用 Eclipse 你应该加入 Build_path
------解决方案--------------------
要在eclipse里面把hibernate3.jar包含进来的
------解决方案--------------------
如果你是部署运行,需要在 CLASSPATH里面加上hibernate3.jar ,如果是在IDE中运行,则需要导入
------解决方案--------------------
lib包里面加了,不一定在里的classpath里了呀.
------解决方案--------------------
应该是对应的jar包没有找到,重新导入试试,要是不行,就重新找个可以用的jar包