When I wrote the SSH project today, when I executed the query query = session.createquery (HQL) in a DAO, it did not execute successfully and jumped directly to finally. Then the front desk reported 500 and java.lang.reflect.InvocationTargetException errors.
The code is as follows:
PackageDAO;Importjava.util.List;Importmodel. AccountInfo;Importorg.hibernate.HibernateException;ImportOrg.hibernate.Query;Importorg.hibernate.Session;Importorg.hibernate.Transaction;Importutil. Hibernateutil; Public classAccountdao { PublicBoolean checkpassword (String account,string Password) {Session session=hibernateutil.getsession (); Transaction Tran=NULL; List<AccountInfo> list =NULL; Try{Tran=session.begintransaction (); String hql= "from AccountInfo as a where a.account=:username"; Query Query=session.createquery (HQL); Query.setstring ("Username", account); List=query.list (); Tran.commit (); }Catch(Hibernateexception He) {tran.rollback (); He.printstacktrace (); }finally{session.close (); } if(List.size () ==0 | |!password.equals (list.get (0). GetPassword ()))return false; Else return true; }}
In fact, however, there is no egg relationship with the code "( ̄▽ ̄)" ". I used MyEclipse installed Hibernate4 Lib Antlr-2.7.7.jar and struts2 Lib Antlr-2.7.2.jar conflict, delete the latter can be.
Session.createquery () not executed and java.lang.reflect.InvocationTargetException