我有这两个实体 许可证
@Entity
@Table(name = "PERMITS")
public class Permit extends AbstractEntity<Long> {
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="USR_ID")
private User user;
用户
@Entity
@Table(name = "USERS")
public class User extends AbstractEntity<Long> {
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
@OrderBy("role ASC")
private List<Permit> permits;
public List<Permit> getPermits() {
return permits;
}
public void setPermits(List<Permit> permits) {
this.permits = permits;
}
// getters, setters etc ...
当我加载它们时
entityManager.createQuery("SELECT u FROM User u JOIN FETCH u.permits")
或与任何其他方法许可属性始终为空。我会理解它是否是一些 PersistentBag 但它是空的,当我为它分配新的 ArrayList 时,它不会被覆盖,所以似乎休眠对这个属性没有任何作用。从另一边(来自许可证)它工作正常。当我做
entityManager.createQuery("SELECT p FROM Permit p")
我看到所有获取用户的许可。我的映射有什么问题?