-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteria request and join tables
PostPosted: Thu Oct 01, 2009 4:10 am 
Newbie

Joined: Mon Sep 21, 2009 2:51 am
Posts: 5
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 ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.