I have an Order
class that has a list of OrderTransactions
and I mapped it with a one-to-many Hibernate mapping like so:
@OneToMany(targetEntity = OrderTransaction.class, cascade = CascadeType.ALL)
public List<OrderTransaction> getOrderTransactions() {
return orderTransactions;
}
These Order
s also have a field orderStatus
, which is used for filtering with the following Criteria:
public List<Order> getOrderForProduct(OrderFilter orderFilter) {
Criteria criteria = getHibernateSession()
.createCriteria(Order.class)
.add(Restrictions.in("orderStatus", orderFilter.getStatusesToShow()));
return criteria.list();
}
This works and the result is as expected.
Now here is my question: Why, when I set the fetch type explicitly to EAGER
, do the Order
s appear multiple times in the resulting list?
@OneToMany(targetEntity = OrderTransaction.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
public List<OrderTransaction> getOrderTransactions() {
return orderTransactions;
}
How would I have to change my Criteria code to reach the same result with the new setting?