Hi,
I have 3 SQL tables : staff, staff_event and event. Between staff and event, it is a @ManyToMany relationship. But because there is an extra column in staff_event, I can't defined a @ManyToMany relationship but two @ManyToOne relationship.
So I have 4 classes :
class staff { @OnToMany(mappedBy = "pk.staff") Set<StaffEvent> staffEvents; }
class StaffEvent{ StaffEventPk pk @EmbeddedId StaffEventPk getpk(){} }
class StaffEventPk { Staff staff Event event }
and
class Event { @OnetoMany(mappedBy = "pk.event") List<StaffEvent> staffs
@Column int week; }
I want now to get all events related to a specific staff where the event.week is specific too.
I use criteria to build my sql request. But I didn't managed to build a correct request.
criteria = createCriteria(this.classFromType(this.ctType),"staff"); criteria.add(Restrictions.eq("staff.id", s.getId())); eventCriteria = criteria.createCriteria("staff.staffEvents", "s_evts").setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); eventCriteria.add(Restrictions.like("s_evts.pk.event.weeks", week));
If i used the following code, it say the it could not resolv property weeks.
So my question is : how to make a criteria request with a join table in the middle ?
|