In the class "Ticket" we have a relation with TicketLine:
Code:
@OneToMany(targetEntity = TicketLine.class, fetch = FetchType.EAGER)
@Fetch(org.hibernate.annotations.FetchMode.JOIN)
@Cascade ....
@IndexColumn(name = "line_index")
public List<TicketLine> getLines() {
return ticketlines;
}
The following two queries return different results
1. HQL
Code:
Srting sql = "from Ticket where dateClose is null "
+ "and host = ?"
+ "and place = ?";
q = session.createQuery(sql)
.setString(0, AppConfig.getInstance().getHost())
.setEntity(1, place);
List<Ticket> tickets = q.list();
Result: tickets contains 2 tickets as expected. Ticket 1 has 3 ticketlines, Ticket 2 has 5 ticketlines.
2. Criteria API
Quote:
Criteria crit = session.createCriteria(Ticket.class);
crit.add(Restrictions.isNull("dateClose"));
crit.add(Restrictions.eq("host", AppConfig.getInstance().getHost()));
crit.add(Restrictions.eq("place", place));
List<Ticket> tickets = crit.list();
Result: tickets contains 8 tickets, i.e. the JOIN is fully reflected and the result set contains 1 Ticket for each line.
Is this a bug or am I missing something?