您的位置:首页 > 其它

unexpected token: * near line 1, column 8 [select * from t_user where 1=1]

2016-01-26 11:23 441 查看
unexpected token: * near line 1, column 8 [select * from t_user where 1=1]      和

users is not mapped 

这个错误可能是因为以下原因导致:

1.在hibernate里面写sql执行时候要用了session.createQuery(sql); 需要用session.createSQLQuerysql);

2.在hibernate里面写hql执行是误把hql写成了sql,比如说:select * , from 表名,hibernate框架操作数据库的核心就是:用操作数据对象代替操作表,给程序员的感觉是面向对象操作数据库。所以查询语句from后面接的不是表名称,而是javabean数据对象名。

映射对象 addEntity

String hql = "select b.* from book_info b,videos_info v where b.userId='"
+userId+ "' and b.videoId=v.global_id and v.video_type="+videoStatus;
Session session = getSession();
SQLQuery query = session.createSQLQuery(hql).addEntity(Book.class);

List<Book> list = (List<Book>)query.list();

String hql2 = "select b.* from book_info b,zhibo_video_info z where b.userId='"
+userId+ "' and b.videoId=z.videoId and z.status='"+videoStatus+"'";
query = session.createSQLQuery(hql2).addEntity(Book.class);
List<Book> list2 = (List<Book>)query.list();
if(list2==null || list2.size()<=0)
return list;
else if(list==null || list.size()<=0)
return list2;
else{
for(int i=0; i<list2.size(); i++){
list.add(list2.get(i));
}
return list;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: