Ok, lets say I have order and items tables. This is how items are described in my Order class:
@ManyToMany(cascade=CascadeType.PERSIST)
@JoinTable(name="MY_ORDER_ITEM_BRIDGE",
joinColumns=@JoinColumn(name="bridge_order_id",referencedColumnName = "order_order_id"),
inverseJoinColumns = @JoinColumn(name="bridge_item_id", referencedColumnName="item_item_id"))
private List<Item> items;
This works fine. But lets image that there is a date in the bridge table called MY_ORDER_ITEM_BRIDGE.expiration_date.
I want to change the definition to only include Items with expiration_date that has not occurred yet.
So I want the generated SQL to look something like:
SELECT *
FROM order o
join my_order_item_bridge b
on b.bridge_order_id = o.order_order_id
join item i
on i.item_item_id = b.bridge_item_id
where b.expiration_date < sysdate;
I am using Ebean, Play Framework 2.1.3. Thanks for any help.
UPDATE: Alternatively, it could also be a second condition on either of the joins:
SELECT *
FROM order o
join my_order_item_bridge b
on b.bridge_order_id = o.order_order_id
and b.expiration_date < sysdate
join item i
on i.item_item_id = b.bridge_item_id
(If possible I'd like to do this in the class definition not in raw SQL)