Tenho duas entidades Actor e Event.
–Actor–
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name="name", length=40, nullable=false)
private String fullName;
@Column(name="description", length=100, nullable=true)
private String description;
@OneToMany(targetEntity=Contact.class, mappedBy="actor", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
private Collection<Contact> contacts;
@OneToMany(targetEntity=Event.class, mappedBy="origination", cascade=CascadeType.REFRESH, fetch=FetchType.LAZY)
private Collection<Event> eventsFromOrigination;
@OneToMany(targetEntity=Event.class, mappedBy="destination", cascade=CascadeType.REFRESH, fetch=FetchType.LAZY)
private Collection<Event> eventsFromDestination;
//----------------
–Event–
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ManyToOne(targetEntity=CategoryItem.class, optional=false)
private CategoryItem categoryItem;
@ManyToOne(targetEntity=Actor.class, optional=false)
private Actor origination;
@ManyToOne(targetEntity=Actor.class, optional=false)
private Actor destination;
@Column(name="event_date", nullable=false)
@Temporal(javax.persistence.TemporalType.DATE)
private Date eventDate;
@Column(name="amount", nullable=false)
private Double amount;
@Column(name="comment", nullable=true, length=100)
private String comment;
//-----------------
Quero recuperar todos os eventos dentro de um determinado período de datas agrupados por ator. Usando SQL ficaria da seguinte maneira.
select * from actor a inner join event e on e.origination_id = a.id
where e.event_date between '2009-12-01' and '2009-12-15'
Criei uma HQL que seleciona todos os atores e seus respectivos eventos num determinado período.
select actor from Actor as actor inner join actor.eventsFromOrigination as origination
with origination.eventDate between :param1 and :param2 group by actor
O problema é que ela recupera aqueles atores (origination) que participaram de eventos dentro do período informado mas na hora que que acesso actor.getEventsFromOrigination() eu recebo uma lista com todos os eventos independentemente do período.
Alguém pode ajudar?