Hi,
Im new to Hibernate and have a question about how to do an inner join on a HQL query between multiple objects.
So this is my object structure - I have a Container class which contains a list of broadcasts and users:
Code:
@Entity
@Table(name = "CONTAINER")
@XmlRootElement
public class Container implements Serializable {
@OneToMany(mappedBy = "container", fetch = FetchType.EAGER)
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@Fetch(value = FetchMode.SELECT)
private List<ProgrammeBroadcast> broadcasts = newArrayList();
ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "CONTAINER_USER_LINK", joinColumns = @JoinColumn(name = "CONTAINER_ID"),
inverseJoinColumns = @JoinColumn(name = "USER_ID"))
@Fetch(value = FetchMode.SELECT)
private List<User> assignedUsers = newArrayList();
Now iv written a query that is working fine that basically returns all Containers that have an assignedUser equal to a given field:
Code:
List<Container> containers = (List<Container>) session
.createQuery("select con from Container as con inner join con.assignedUsers au where au.id = ? ")
.setParameter(0, searchCriteria.getUser().getId())
.setCacheable(true)
.list();
What I want to do is add a further restriction which basically only picks dates which are in a given time period in the ProgrammeBroadcast object (called scheduledStartTime). This is what I have written but its not working:
Code:
List<Container> containers = (List<Container>) session
.createQuery("select con from Container as con inner join con.assignedUsers au where au.id = ? and con.broadcasts br where br.scheduledStartTime > ? ")
.setParameter(0, searchCriteria.getUser().getId())
.setParameter(1, searchCriteria.getFromDate())
.setCacheable(true)
.list();
It returns this error - org.hibernate.hql.ast.QuerySyntaxException: unexpected token: br near line 1, column 129 [select con from com.redbeemedia.subtitling.Container as con inner join con.assignedUsers au where au.id = ? and con.broadcasts br where br.scheduledStartTime > ? ]
If someone could let me know what I am doing wrong it would be much appreciated!
Thanks,