DetachedCriteria 关联查询出错,求解答

blueshy 发布于 2015/09/15 15:32
阅读 130
收藏 0
@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,求解答,感激不尽。

加载中
0
王涛
王涛

这样用真的可以吗?

返回顶部
顶部