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;
}
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;
}
相关文章推荐
- 黑马程序员----九-面向对象四
- 模拟迅雷登陆
- Ubuntu 下的flask+bootstrap 环境搭建
- ServerSocket 默认邦定IP
- 模拟迅雷登陆
- Quartz.NET笔记(六) CronTrigger
- Linux运维-zabbix_agent最新版的yum安装
- BOM对象
- 使用PyCharm Professional Edition开发Flask Web程序
- 关于count(1)和count(*)效率区别和差异
- 黑马程序员----八-面向对象三
- ZOJ 3229 Shoot the Bullet-上下界网络流
- Android L 控件水波纹效果
- RPC原理(公司必备)
- iOS CoreImage 实现二维码生成和识别
- 一张图总结html5新特性
- 深入分析Oracle字符集
- Terrier文档翻译:首页
- background indexer crash recovery java.lang.stackoverflowerror
- CSDN找到:我关注的人