开发者社区> 问答> 正文

DetachedCriteria 关联查询出错,求解答? 报错

DetachedCriteria 关联查询出错,求解答? 400 报错 @Entity
@Table(name="t_applicant")
public class Applicant extends BaseEntity{

@Id
@Column(name="id",nullable=false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;

@Column(name="user_id")
private User user;

public Long getId() {
return id;
}


public void setId(Long id) {
this.id = id;
}


@ManyToOne(cascade={CascadeType.ALL})
@JoinColumn(name="id")
public User getUser() {
return user;
}


public void setUser(User user) {
this.user = user;

}



@Entity
@Table(name="t_user")
public class User extends BaseEntity{

private static final long serialVersionUID = -7962088110132926545L;


@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;


@Column(name = "userName")
@NotBlank(message = "用户名称不能为空.")
private String userName;


public Long getId() {
return id;
}


public void setId(Long id) {
this.id = id;
}


public String getUserName() {
return userName;
}


public void setUserName(String userName) {
this.userName = userName;
}


}


DetachedCriteria dc = DetachedCriteria.forClass(Applicant.class);
dc.createAlias("User", "u",DetachedCriteria.LEFT_JOIN);
dc.add(Restrictions.eq("u.id", 1));
return dc;

报错:could not resolve property: User of: com.sun.entity.Applicant,求解答,感激不尽。

展开
收起
优选2 2020-06-04 21:17:37 619 0
1 条回答
写回答
取消 提交回答
  • 这样用真的可以吗?

    2020-06-05 11:32:51
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载