Hi folks,
I've two Entity (called Price and Room) with a monodirectional (from Price to Room) ManyToMany relationship.
Here the code:
Code:
@Entity
public class Price {
@ManyToMany
@JoinTable(name = "price_room",
joinColumns = {@JoinColumn(name = "price_id") },
inverseJoinColumns = {@JoinColumn(name = "room_id") }
)
@IndexColumn (name = "index_column")
private List<Room> rooms;
}
@Entity
public class Room {
......
}
I would do an OUTER JOIN with Criteria but I can't get it.
I want to retrieve all Room entities that have no Price associated
In SQL it'd be:
Code:
SELECT p.id as price_id, ro.id as room_id
FROM room ro LEFT OUTER JOIN price_room pro ON ro.id = pro.room_id
LEFT OUTER JOIN price p ON p.id = pro.price_id
WHERE p.id is null
I wrote the criteria but it produces an INNER JOIN:
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Price.class);
criteria.add(Restrictions.isNull("id"))
criteria.createAlias("rooms", "room")
Do you know how to make OUTER JOIN?
Thanks a lot