문제

So I have two tables: Users and AlertHistory.

I have joined AlertHistory to User, so that if I do:

 List<User> users = new Model.Finder(Integer.class, User.class).setMaxRows(9).findList();
 List<AlertHistory> ahc = users.get(3).getAlertHistoryCollection();

I will get the list of Users, and each user will have a collection of AlertHistory objects.

What I would like to do with the Finder, is return the list of Users where the AlertHistory is NOT NULL. I've tried various version of:

new Model.Finder(Integer.class, User.class).where().isNotNull("alertHistoryCollection").setMaxRows(9).findList();

but to no avail.

도움이 되었습니까?

해결책

The problem here was that the relationships I had defined weren't correct.

In User.java:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
private List<AlertHistory> alertHistoryList = new ArrayList<>();

and in AlertHistory.java:

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")

Once I got the relationship annotated and typed correctly, it started working as expected, so that if the User has associated AlertHistory's, they will populate, and if not, the collection will be empty. .isNotNull() now works as expected.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top