我正在尝试按JPQL查询声明中的字段排序,这似乎应该很简单,但我一直遇到编译器错误。
我正在尝试通过UserClockDate列进行排序,该列是UserTime行的一部分。但是每次我尝试编译时,都会出现错误:
严重:命名查询中的错误:fetchIfUserIsClockedInWithUser
org.hibernate.QueryException:无法解析属性:
UserClockDate的:models.UserTime [从models.UserTime ut选择SELECT ut
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;
您能给我的任何帮助将不胜感激!
最佳答案
您是说要尝试按不存在的字段进行订购? UserClockDate应该是userClockDate