今天在做一个功能的时候 
遇到了。一个Could not resolve property 的问题。

配置文件如下:

  1. <many-to-one name="user"  class="Users" column="StudentExam_user_fid" cascade="all" ></many-to-one>

查询代码:

  1. Criteria crt = session.createCriteria(StudentExam.class).add(Restrictions.eq("exam.id", ExamId)).add(
  2. Restrictions.eq("reading", reading)).add(Restrictions.like("user.truename", name));
  3. return crt.setFirstResult(start).setMaxResults(max).list();

在网上找了好久。所有人给的理由都是“对照配置文件以及实体类,是否写错了字段名称” 
在我一再的确认下,字段名称没有任何错误…… 
而且使用user.id是可以进行查询的。除了这个以外。别的都不可以用! 
于是开始对配置文件进行修改。尝试了 lazy设置为false 等等。。想对应的修改 
Users配置文件的修改。未果

最后,经过各种挣扎。以及Hibernate相关API的查找。最终终于找出解决办法

  1. Criteria crt = session.createCriteria(StudentExam.class).add(Restrictions.eq("exam.id", ExamId)).add(
  2. Restrictions.eq("reading", reading)).createCriteria("user").add(Restrictions.like("truename", name));

对。就是这样写。在使用完StudentExam里的属性后。

  1. .createCriteria("user")

设置到user实体里。然后再选择属性 
注:这里的user是StudentExam类中的名称

注意一般情况下都是 user这个类的关系

many to one could not resolve property的更多相关文章

  1. nested exception is org.hibernate.QueryException: could not resolve property

    SSH框架出现了下面的错误: nested exception is org.hibernate.QueryException: could not resolve property 检查了hbm.x ...

  2. org.hibernate.QueryException: could not resolve property

    org.hibernate.QueryException: could not resolve property HibernateSQLXML  org.hibernate.QueryExcepti ...

  3. org.hibernate.QueryException: could not resolve property: address of:

    Hibernate: select count(*) as y0_ from test.course this_ org.hibernate.QueryException: could not res ...

  4. could not resolve property问题(ssh框架)

    could not resolve property不能解析属性问题, 刚开始把hql语句中的"from User user where user.user_name = '"+u ...

  5. could not resolve property: leader_id of: pojo.Project

    https://www.cnblogs.com/zhaocundang/p/9211270.html hibernate 双向1对多 出现问题 外键解析错误! log4j:WARN No append ...

  6. could not resolve property

    could not resolve property(无法解析属性) 顾名思义在写hql语句的时候,属性写错了! 请检查大小写,是实体类的,不是数据库表的! 一个一个检查,仔细看!

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

    正确写法: @Override @SuppressWarnings("unchecked") public List<Device> queryOSDevice(Str ...

  8. could not resolve property(无法解析属性)

    could not resolve property(无法解析属性) 顾名思义在写hql语句的时候,属性写错了! 请检查大小写,是实体类的,不是数据库表的! 一个一个检查,仔细看!

  9. Hibernate-org.hibernate.QueryException: could not resolve property: code of:

    查询的时候有个属性跟表里的字段不符合,没有完全匹配上.

随机推荐

  1. [百度空间] [转]关于Direct3D多窗口编程的一篇翻译

    Introduction In DirectX 8, support for rendering to multiple windows is provided through the creatio ...

  2. ActionScript基本语法讲解

    var a:int = 3;var b:int = 4; b = 9; trace ("a的值为:"+a);trace ("b的值为:"+b); var x1: ...

  3. 【ASP.Net MVC】AspNet Mvc一些总结

    AspNet Mvc一些总结 RestaurantReview.cs using System; using System.Collections.Generic; using System.Comp ...

  4. Base64编解码Android和ios的例子,补充JNI中的例子

    1.在Android中java层提供了工具类:android.util.Base64; 里面都是静态方法,方便直接使用: 使用方法如下: // Base64 编码: byte [] encode =  ...

  5. POJ 1548 Robots (Dilworth)

    Robots Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 3621 Accepted: 1643 Description Yo ...

  6. LoaderManager使用详解(四)---实例:AppListLoader

    实例:AppListLoader   这篇文章将是我的第四篇,也就是最后一篇该系列的文章.请在评论里面告诉我他们是否有用.前面几篇文章的链接如下:   一:Loaders之前世界 二:了解Loader ...

  7. EF框架批量更新

    var customers = db.Customers.Where(c => c.name=='小明'); foreach (var customer in customers) { cust ...

  8. C# 6 —— 属性

    记录一下 C# 6 有关属性的语法糖实现,C# 6 涉及到属性的新特性主要有 2 个:自动属性初始化.只读属性赋值与读取. 自动属性初始化(Auto-property initializers) C# ...

  9. HDU4003 Find Metal Mineral 树形DP

    Find Metal Mineral Problem Description Humans have discovered a kind of new metal mineral on Mars wh ...

  10. sql server 2008 评估期已过期解决办法

    开始-->所有程序-->Microsoft SQL Server 2008-->配置工具-->SQL Server 安装中心-->维护-->版本升级,接着按照提示一 ...