跪求解答:javaweb中SSH框架dao层的session.createQuery(hql);不运行
publicclassUserDaoimplextendsHibernateDaoSupportimplementsUserDao{publicListuserlogin...
public class UserDaoimpl extends HibernateDaoSupport implements UserDao {
public List userlogin(final Users users) {
System.out.println("dao");
String hql = "from Users as a where a.name=? and a.password=?";
System.out.println("-------------");
Session session = this.getSessionFactory().openSession();
if(session!=null){
System.out.println("Good!获取到了session"+
"打开的吗?"+session.isOpen()+" 连接的吗?"+
session.isConnected());
}else{
System.out.println("session获取失败");
}
System.out.println("000000000");
Query query = session.createQuery(hql);
System.out.println("111111111");
query.setString(0, users.getName());
query.setString(1, users.getPassword());
System.out.println("222222222");
List list = query.list();
return list;
这是dao层的代码
下面的后台打印
dao
-------------
Good!获取到了session打开的吗?true 连接的吗?true
000000000
Query query = session.createQuery(hql);这句为什么不执行呢???求大神解答
错误:
HTTP Status 500 -
java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
测试用:
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
UserBiz userBiz = (UserBiz)applicationContext.getBean("userbiz");
Users users = new Users();
users.setName("gq2");
users.setPassword("gq2");
List list = userBiz.login(users);
if (list.isEmpty()){
System.out.println("failure");
}else{
System.out.println("success");
}
}
后台打印是:
dao
-------------
Good!获取到了session打开的吗?true 连接的吗?true
000000000
111111111
222222222
success 展开
public List userlogin(final Users users) {
System.out.println("dao");
String hql = "from Users as a where a.name=? and a.password=?";
System.out.println("-------------");
Session session = this.getSessionFactory().openSession();
if(session!=null){
System.out.println("Good!获取到了session"+
"打开的吗?"+session.isOpen()+" 连接的吗?"+
session.isConnected());
}else{
System.out.println("session获取失败");
}
System.out.println("000000000");
Query query = session.createQuery(hql);
System.out.println("111111111");
query.setString(0, users.getName());
query.setString(1, users.getPassword());
System.out.println("222222222");
List list = query.list();
return list;
这是dao层的代码
下面的后台打印
dao
-------------
Good!获取到了session打开的吗?true 连接的吗?true
000000000
Query query = session.createQuery(hql);这句为什么不执行呢???求大神解答
错误:
HTTP Status 500 -
java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
测试用:
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
UserBiz userBiz = (UserBiz)applicationContext.getBean("userbiz");
Users users = new Users();
users.setName("gq2");
users.setPassword("gq2");
List list = userBiz.login(users);
if (list.isEmpty()){
System.out.println("failure");
}else{
System.out.println("success");
}
}
后台打印是:
dao
-------------
Good!获取到了session打开的吗?true 连接的吗?true
000000000
111111111
222222222
success 展开
2个回答
展开全部
session.createQuery(hql) hql 你确定你写的hql 里面的是Users 是对象名不是表名
name,password是属性名不是列名?
name,password是属性名不是列名?
更多追问追答
追问
import com.gq.entity.Users;
是类别不是表,name,password是属性名
追答
from Users where name=? and password=? hql换下试一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String hql = "from Users as a where a.name=? and a.password=?";
检查一下:
Users 指一个类别,而不是资料表
检查一下:
Users 指一个类别,而不是资料表
更多追问追答
追问
import com.gq.entity.Users;
是类别不是表
追答
String hql = "from Users as a where a.name=? and a.password=?";
改为
String hql = "from Users where name=? and password=?";
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询