【发布时间】:2016-09-19 07:04:11
【问题描述】:
我想查找城市名称等于 Madrin 的所有计划(例如)。 但我总是得到一个错误。
org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.hibernate.QueryException: could not resolve property: location.lName of: io.onek.entity.FuturePlan.
帮我弄清楚。
未来计划
@Entity
public class FuturePlan {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int fpId;
private String about;
@DateTimeFormat(pattern = "dd-mm-yyyy")
@Temporal(TemporalType.DATE)
private Date travelDate;
@ManyToOne(fetch=FetchType.EAGER)
private User user;
@ManyToOne(fetch=FetchType.EAGER)
private Location location;
public FuturePlan() {
super();
}
public FuturePlan(String about, Date travelDate) {
super();
this.about = about;
this.travelDate = travelDate;
}
public FuturePlan(String about, Date travelDate, User user, Location location) {
this.about = about;
this.travelDate = travelDate;
this.user = user;
this.location = location;
}
..get/set/
位置
@Entity
public class Location {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int lId;
private String lName;
public Location() {
super();
}
public Location(int lId, String lName) {
super();
this.lId = lId;
this.lName = lName;
}
来自我的 DAOImpl 的方法。
@Override
public List<FuturePlan> findByLocation(String name) {
Session session = sessionFactory.openSession();
Criteria cr = session.createCriteria(FuturePlan.class);
cr.add(Restrictions.eq("location.lName", name));
List<FuturePlan> list = cr.list();
session.close();
return list;
}
【问题讨论】:
标签: java hibernate spring-mvc