質問

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