Users is not mapped 网上查了好多也没解决
按照老师的来 到登录的那一步老是报 Users is not mapped [from Users u where u.username=? and u.password=? ]
按照老师的来 到登录的那一步老是报 Users is not mapped [from Users u where u.username=? and u.password=? ]
2015-09-23
hibernate 5这样写
//创建配置对象(读取配置文档)
Configuration config = new Configuration().configure();
//创建会话工厂对象
sessionFactory = config.buildSessionFactory();
//会话对象
session = sessionFactory.openSession();
//开启事务
transaction = session.beginTransaction();
---------------------
作者:ninelie
来源:CSDN
原文:https://blog.csdn.net/ninelie/article/details/52654934
版权声明:本文为博主原创文章,转载请附上博文链接!
public boolean usersLogin(Users u) {
// TODO Auto-generated method stub
Transaction tx = null;
String sql = "";
try
{
Session session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
sql = "select * from users where username=? and password=? ";
表名不区分大小写
Query query = session.createSQLQuery(sql);
query.setParameter(0, u.getUsername());
query.setParameter(1, u.getPassword());
List list = query.list();
tx.commit();
if(list.size()>0)
{
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
ex.printStackTrace();
return false;
}
finally
{
if(tx!=null)
{
//tx.commit();
tx = null;
}
}
}
用SQL 可以
举报