我正在尝试按 JPQL 查询声明中的字段进行排序,看起来它应该非常简单,但我不断收到编译器错误。
我正在尝试按 UserClockDate 列排序,该列是 UserTime 行的一部分。但是每次我尝试编译时都会出现错误:
严重:命名查询中的错误:fetchIfUserIsClockedInWithUser org.hibernate.QueryException:无法解析属性:UserClockDate of:models.UserTime [SELECT ut FROM models.UserTime ut WHERE USER_ID = :user ORDER BY ut.UserClockDate DESC]
如果我只是取出 ORDER BY 它编译得很好。
这是类本身的相关部分:
@NamedQueries({
@NamedQuery(name = "fetchAllUserTimes", query = "SELECT ut FROM UserTime ut"),
@NamedQuery(name = "fetchIfUserIsClockedInWithUser", query = "SELECT ut FROM UserTime ut WHERE USER_ID = :user ORDER BY ut.UserClockDate DESC")
})
@Entity
@Table(name = "userTime")
@Component
public class UserTime implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "UserTimeId")
private int userTimeId;
@ManyToOne
@JoinColumn(name = "USER_ID")
private User user;
@Column(name = "UserClockIn")
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
private DateTime userClockIn;
@Column(name = "UserClockOut")
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
public DateTime userClockOut;
@Column(name = "UserClockDate")
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
public DateTime userClockDate;
您能给我的任何帮助将不胜感激!