Hi,
I have an entity called Material. It can have many Rental, but only one active at a time (Rental has a column named active = 0/1).
Can I map that using @OneToOne? I'm only interested in the active (if there is one) Rental.
I've tried this in Material:
Code:
@OneToOne(fetch=FetchType.LAZY, mappedBy="material")
public Rental getRental() {
return rental;
}
But that has caused problems with some Materials that have many non-active Rental (and none active):
Quote:
More than one row with the given identifier was found
This mapping is important for a query like this:
Code:
select mat from Material mat
join fetch mat.type type
join fetch type.group group
left join fetch mat.rental rental
where ( (mat.creationDate between :startDate and :endDate) or (mat.state = 41 and rental.active = true and rental.authDate between :startDate and :endDate) )
(Basically, this is just retrieving all materials created or rented in a certain month).
I've seen there are @Where, @Filter and @Formula annotations, but I couldn't find good explanation or examples about their usage.
Thanks.