正确写法:

  @Override
@SuppressWarnings("unchecked")
public List<Device> queryOSDevice(String cpu){
String sql = null;
if(cpu.equals("os_xp")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";
}else if(cpu.equals("os_7")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows7') ";
}else if(cpu.equals("Os_Win8")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows81') ";
}else if(cpu.equals("Os_Win10")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows10InsiderPreview') ";
}else if(cpu.equals("os_vista")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsVista') ";
}else if(cpu.equals("os_2003")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsServer2003') ";
}else if(cpu.equals("os_98")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows98') ";
}else if(cpu.equals("os_95")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows95') ";
}else if(cpu.equals("os_me")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsMe') ";
}else if(cpu.equals("os_nt")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsNt') ";
}else if(cpu.equals("os_2000")){
sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.Windows2000') ";
}
return getSession().createQuery(sql).list();
}

1、出现“org.hibernate.QueryException: could not resolve property”错误的解决:

  起初,hql语句是这样写的,报错:could not resolve property:osId

 sql = "from "+this.clazz.getName()+" this WHERE this.osId = (select id from cems_dict_os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";

  考虑需要改为  this.os.id ,但是又出现cems_dict_os is not mapped的错误

sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from cems_dict_os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";

2、出现“cems_dict_os is not mapped”错误的解决:

  hql语句都需要从对象里面获取,所以需要将  cems_dict_os  改成它的实体对象  Os

sql = "from "+this.clazz.getName()+" this WHERE this.os.id = (select id from Os o where o.name = 'com.vrv.common.system.os.WindowsXP') ";

3、org.hibernate.QueryParameterException: could not locate named parameter [ip]

  其实自己去检查一下SQL语句就可以了

  ①:参数不正确,基本上是" 实体属性=:参数属性 "(尤其是冒号:这个大家会经常丢掉)

  ②:画蛇添足,没有这个参数,自己认为新增的参数,导致找不到

  我导致这个问题的原因是:and this.ip = :ip 写成了 this.ip = ? ;此外注意:  =:参数属性  ;冒号和参数属性之间不能有空格

4、SSH框架问题——node to traverse cannot be null!报错问题:java.lang.IllegalArgumentException: node to traverse cannot be null!

  这个错误一般是sql、hql语句有问题,比如关键字书写问题,语法问题等,本人犯了一个低级错误,使用update的时候,给多个属性赋值需要使用“,”(逗号)隔开。

5、org.hibernate.QueryException: Not all named parameters have been set: [name]:

if(!"".equals(name)){
sql += "and this.name = :name ";
}
osDevice = getSession().createQuery(sql).setParameter("name",name).list();

  这样写就会报这个错误,原因是:hibernate 执行sql时没有找到相应的参数名,改为下面这样既可:

if(!"".equals(name)){
sql += "and this.name = '" + name + "'";
}
osDevice = getSession().createQuery(sql).list();

常见Hibernate报错处理:出现“org.hibernate.QueryException: could not resolve property”和 is not mapped和could not locate named parameter错误的解决的更多相关文章

  1. 关于MyEclipse启动报错:Error starting static Resources;下面伴随Failed to start component [StandardServer[8005]]; A child container failed during start.的错误提示解决办法.

    最后才发现原因是Tomcat的server.xml配置文件有问题:apache-tomcat-7.0.67\conf的service.xml下边多了类似与 <Host appBase=" ...

  2. Hibernate报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解决办法

    报错信息: org.hibernate.event.internal.DefaultLoadEventListener onLoad INFO: HHH000327: Error performing ...

  3. Hibernate报错,关于配置的SessionFactory找不到问题

    最近写项目使用hibernate默认的dtd,在启动项目时经常会出现这个问题,hibernate报错,配置factory的id找不到,找不到mapping配置文件, 不能读取配置的xml文件 Coul ...

  4. Hibernate报错:Caused by: java.sql.SQLException: Field 'ID' doesn't have a default value

    问题一: 报错如下: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assig ...

  5. linux运维常见英文报错中文翻译(菜鸟必知)

    linux常见英文报错中文翻译(菜鸟必知) 1.command not found  命令没有找到 2.No such file or directory  没有这个文件或目录 3.Permissio ...

  6. Linux常见英文报错中文翻译(菜鸟必知)

    Linux常见英文报错中文翻译(菜鸟必知) 1.command not found 命令没有找到 2.No such file or directory 没有这个文件或目录 3.Permission ...

  7. Linux常见英文报错中文翻译

    Linux常见英文报错中文翻译(菜鸟必知) 1.command not found 命令没有找到 2.No such file or directory 没有这个文件或目录 3.Permission ...

  8. python中常见的报错信息

    python中常见的报错信息 在运行程序时常会遇到报错提示,报错的信息会提示是哪个方向错的,从而帮助你定位问题: 搜集了一些python最重要的内建异常类名: AttributeError:属性错误, ...

  9. Python中常见的报错名称

    Python中常见的报错名称 1.SyntaxError 语法错误.看看是否用Python关键字命名变量,有没有使用中文符号,运算符.逻辑运算符等符号是不是使用不规范. 2.IndentationEr ...

随机推荐

  1. Django【进阶】序列化

    关于Django中的序列化主要应用在将数据库中检索的数据返回给客户端用户,特别的Ajax请求一般返回的为Json格式. 方案一:serializers 1 2 3 4 5 fromdjango.cor ...

  2. Kuangbin 带你飞专题十一 网络流题解 及模版 及上下界网络流等问题

    首先是几份模版 最大流:虽然EK很慢但是优势就是短.求最小割的时候可以根据增广时的a数组来判断哪些边是割边.然而SAP的最大流版我只会套版,并不知道该如何找到这个割边.在尝试的时候发现了一些问题.所以 ...

  3. python基础===pip安装模块失败

    此情况只用于网络不畅的安装模块背景: 总出现红色的 Could not find a version that satisfies the requirement pymongo(from versi ...

  4. Qt笔记——入门

    Qt的介绍 跨平台c++图形用户界面应用程序框架 Qt的框架 父类(基类)子类(派生类) 头文件 QApplication应用程序类 Qt头文件没有.h 头文件和类名一样 有且只有一个应用程序类的对象 ...

  5. Qt笔记——Event

    #ifndef MYBUTTON_H #define MYBUTTON_H #include <QPushButton> class MyButton : public QPushButt ...

  6. [loj #6003]「网络流 24 题」魔术球 二分图最小路径覆盖,网络流

    #6003. 「网络流 24 题」魔术球 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测试数据 ...

  7. 【互动问答分享】第11期决胜云计算大数据时代Spark亚太研究院公益大讲堂

    Q1:docker成熟度如何? Docker是2013年和2014年最火爆的云计算开源项目: Baidu公司是中国使用Docker最为深入和最大规模的公司,线上稳定运行数十万个Docker容器,目前已 ...

  8. docker容器间通信

    现在在我们的docker中已经有了三个容器,分别是DB/API/UI三个容器,三个容器间肯定是要进行互相通信的 可以查看docker的官方文档,https://docs.docker.com/engi ...

  9. python3爬虫爬取猫眼电影TOP100(含详细爬取思路)

    待爬取的网页地址为https://maoyan.com/board/4,本次以requests.BeautifulSoup css selector为路线进行爬取,最终目的是把影片排名.图片.名称.演 ...

  10. 线段树【CF620E】The Child and Sequence

    Description At the children's day, the child came to Picks's house, and messed his house up. Picks w ...