Categories
hibernate hql java many-to-many sql

Hibernate many-to-many join with condition

+-------+    +--------------|     +-------+
| BOY | | BOY_GIRL | | GIRL |
+-------+ +--------------| +-------+
| id | | id | | id |
| name | | boy_id | | name |
| birth | | girl_id | | birth |
+-------+ | start_dating | +-------+
+--------------|

START_DATING is type of TIMESTAMP or DATE

I have two beans Boy and Girl with many-to-many relation

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "BOY_GIRL", joinColumns = {@JoinColumn(name = "BOY_ID")}, inverseJoinColumns = {@JoinColumn(name = "GIRL_ID")})
public Set<Girl> getGirls() {
return girls;
}

Now, how can I do select query with HQL, if I want to get the list girls with condition:

where boy_id = (some_boy_id) and START_DATING > (some_timestamp)