我是休眠新手,我的表格如下:
Tb_User
- 用户 ID (PK)
- 用户名
- 用户姓氏
- 用户登录
- 用户密码
Tb_Order
- 订单编号 (PK)
- 用户 ID(逻辑外键)
- 订购日期
- 订单备注
我的道课的作用:
public List<TbOrder> getUserOrdering(TbOrder tbOrder) throws Exception{
Criteria _criteria = getSession().createCriteria(TbOrder.class);
if(tbOrder.getUserId() != null)
_criteria.add(Restrictions.eq("UserId", tbOrder.getUserId()));
return (List<TbOrder>) _criteria.list();
}
我的实体类:
class TbOrder {
Long orderId;
Long userId;
public TbOrder(){
}
public TbOrder(Long orderId, Long userId){
this.orderId = orderId;
this.userId = userId;
}
public Long getOrderId() {
return orderId;
}
public void setOrderId(Long orderId) {
this.orderId = orderId;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
}
class TbUser{
private Long userId;
private String userFirstName;
private String userLastName;
private String userLogin;
private String userPwd;
public TbUser() {
}
public TbUser(Long userId, String userFirstName, String userLastName,
String userLogin, String userPwd) {
this.userId = userId;
this.userFirstName = userFirstName;
this.userLastName = userLastName;
this.userLogin = userLogin;
this.userPwd = userPwd;
}
public Long getUserId() {
return userId;
}
public void setUserId(Long userId) {
this.userId = userId;
}
public String getUserFirstName() {
return userFirstName;
}
public void setUserFirstName(String userFirstName) {
this.userFirstName = userFirstName;
}
public String getUserLastName() {
return userLastName;
}
public void setUserLastName(String userLastName) {
this.userLastName = userLastName;
}
public String getUserLogin() {
return userLogin;
}
public void setUserLogin(String userLogin) {
this.userLogin = userLogin;
}
public String getUserPwd() {
return userPwd;
}
public void setUserPwd(String userPwd) {
this.userPwd = userPwd;
}
}
假设 Tb_Order.UserId 应该设置为链接到 Tb_User 的外键,但由于某些原因,我不能这样做。
但是,这是我的情况,我想获取下订单的用户的名字和姓氏,id=1001,以及订单的日期和备注。通常,当我在谷歌搜索一段时间时,有人告诉我我可以尝试id.userid
获取 Tb_User 对象,但是,我没有得到任何由休眠生成的 Id 类,它应该是。那么,请告诉我获取订单和用户信息的最佳方式是什么?谢谢!