我想检索在某个特定列上排序的子对象。
我有家长班学生
public class Student {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="STUDENT_ID")
private long studentId;
@Column(name="STUDENT_NAME")
private String studentName;
@OneToMany(mappedBy="student")
private List<Phone> studentPhoneNumbers ;
}
和子类电话
public class Phone {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="PHONE_ID")
private long phoneId;
@Column(name="PHONE_NO")
private String phoneNumber;
@Column(name ="UPDATE_TMSTP")
private Date updateTmstp;
@ManyToOne
@JoinColumn(name = "STUDENT_ID")
private Student student;
}
我正在获取 Student 对象,这反过来给了我电话号码列表。updateTmstp
我希望根据我写的这个列对这些电话号码进行排序
Student stu = (Student)session.createCriteria(Student.class)
.createAlias("studentPhoneNumbers", "st").addOrder(Order.desc("st.updateTmstp")).uniqueResult();
但它不起作用。有人能帮我吗。我做错什么了吗?