我有两张桌子hesk_users
,user
如下所示。
@Entity @Table(name="hesk_users") 公共类 UserHesk {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column
private int id;
@OneToOne
@JoinColumn(name="user_id")
private User user;
set.... get..
}
@Entity @Table(name="user") 公共类用户实现可序列化 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@NotEmpty
@Column
private String firstname;
@OneToOne(mappedBy="user")
private UserHesk userHesk;
set ... get ...
}
我有休眠查询,但它不起作用..
DetachedCriteria detachedCriteria=DetachedCriteria.forClass(UserHesk.class)
.setProjection(Projections.property("user_id"));
Criteria criteria=sessionFactory.getCurrentSession().createCriteria(User.class);
criteria.add(Property.forName("id").notIn(detachedCriteria));
User user=(User)criteria.list().get(0);
System.out.println(user.getFirstname());
System.out.println("Subquery Size "+criteria.list().size());
user_id
归档错误。由于关系无法得到。