2013年12月4日星期三

Hibernate HQL does not perform nor thrown

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;
}
------ Solution ----------------------------------- ---------
Query query = session.createQuery ("from Course course where course.CId = ");?
------ Solution --------- -----------------------------------
this one seems to be a problem . . . session = HibernateSessionFactory.currentSession ();
------ For reference only --------------------------- ------------
I started using this setup parameters query.setInteger (0, cid);
same problem
------ For reference only ------------------------------ ---------
Query query = session.createQuery ("from Course course where course.CId =?");
---- - For reference only ---------------------------------------
Query query = session.createQuery("from Course course where CId =?");

landlord to have used the alias of the original table fields can not be used to get there is to look HibernateSessionFactory the session is empty
------ For reference only - --------------------------------------
Nima Why do not allow users to change color the

------ For reference only ---------------------------------- -----
debug
run to go in and see what the problem is and then there is the screenshot we look
------ For reference only -------------------- -------------------
hql try to change the sentence , the phrase hql see if it is a problem , or hql query the table in question , the amount of data is too or how big lead .
------ For reference only -------------------------------------- -
look session is not null ah

没有评论:

发表评论