I have following classes-tables with onetomany relationships
People
@Entity
public class People{
@Id @Column private Integer id;
@Column(name="FNAME") private String fName;
@Column(name="LNAME") private String lName;
@OnetoMany(targetEntity=Registration.class, mappedBy="pId", cascade.....)
private Set<Registrations> registrations;
//getters and setters
}
Events
@Entity
public class Events{
@Id @Column private Integer id;
@Column(name="NAME") private String name;
@Column(name="DATE") private Timestamp date;
@OnetoMany(targetEntity=Registration.class, mappedBy="eId", cascade.....)
private Set<Registrations> registrations;
//getters and setters
}
Registrations
@Entity
public class Registrations{
@Id @Column private Integer id;
@Manytoone @JoinColumn(name="pid" ) private Person person;
@Manytoone @JoinColumn(name="eid" ) private Event event;
//getters and setters
}
So in the input form when the user enters a list of "event id", I need to return a list of people who attended those events.. how to write query for this type? I have this so far..
from Person p join p.registations r where r.event.id in (:eventIdlist)"
but I think it returns both person and refistration objects.. cause when I did this List person = query.list() I got cannot cast kind of error.. I just need person object list..