I have a question regarding Hibernate that's been bothering me for some time. Consider I have two entities:
@Entity
public class Statement {
@Id
@Column
private int id;
@Column
private Date startDate;
@Column
private Date endDate;
@OneToMany
// @JoinFormula???
private List<Transaction> transactions;
...
}
@Entity
public class Transaction {
@Id
@Column
private int id;
@Column
private Date transactionDate;
...
}
As you can see, a Statement
consists of multiple Transaction
s.
Reasonably, the Statement
should contain only Transaction
s that occur between the statement's startDate
and endDate
. This would obviously be dead simple in native SQL (BETWEEN
), but I haven't seen a good solution for mapping this to entities in Hibernate without a hacky @JoinFormula
involving a subquery. Is there a way to do this I don't know about? If a @JoinFormula
is my only option, can I avoid a subquery?