I have two classes:
@Entity
public class Tick {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne(optional = false)
@JoinColumn(name = "elitesystem_id", referencedColumnName = "id")
private EliteSystem eliteSystem;
private Date createDate;
@ManyToOne(optional = true)
@JoinColumn(name = "commander_id", referencedColumnName = "id")
private Commander commander;
private String address;
and
@Entity
public class Note {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne(optional = true)
@JoinColumn(name = "tick_id", referencedColumnName = "id")
private Tick tick;
private String text;
private Date createDate;
I want to select all ticks and get notes if there are any:
Query query = session.createQuery("select t, n from Note n right join n.tick t where t.commander.name = '123'");
List<Object[]> list = query.list();
This returns only Tick objects. What is the correct approach to get the Note information as well in 1 single query? I could put a reference to a Note into the Tick class, but this doesnt sound right, as there are only a few notes, so the column in the Tick table would mostly be empty.