当前位置: 代码迷 >> Java Web开发 >> Hibernate HQL不执行也不抛出错误
  详细解决方案

Hibernate HQL不执行也不抛出错误

热度:6035   发布时间:2016-04-10 23:32:10.0
Hibernate HQL不执行也不抛出异常
public Course getCourse(int cid){
Session session = null;
Transaction tx = null;
List l = null;
Course ct =null;
try{
session = HibernateSessionFactory.currentSession();
tx = session.beginTransaction();
System.out.println(1111111112);
Query query = session.createQuery("from Course course where CId =?");
System.out.println(111111111);
query.setParameter(0, cid);

ct=(Course) query.uniqueResult();
 
query = null;
tx.commit();
}catch(Exception e)
{
e.printStackTrace();
System.out.print(e.getMessage());
}finally
{
if(tx!=null)
tx.rollback();

HibernateSessionFactory.closeSession();

}
return  ct;
}
java hibernate J2ee

------解决方案--------------------
Query query = session.createQuery("from Course course where course.CId =?"); 
------解决方案--------------------
好像是这一句的问题。。。session = HibernateSessionFactory.currentSession();
  相关解决方案