Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: HQL help : from Event e join e.participantsList u where u.us
PostPosted: Mon Aug 20, 2012 10:40 am 
Newbie

Joined: Mon Aug 20, 2012 10:37 am
Posts: 2
I want to get all events in which user participate.
My HQL for it is: from Event e join e.participantsList u where u.userid=:fuserid
but it does not work...help please,pretty please with sugar on top :)

@Entity
public class Event
{
private long eventID;
private Collection<UserData> participantsList;

@Id
@GeneratedValue()
public long getEventID(){return eventID;}
public void setEventID(long eventID){this.eventID = eventID;}

@ManyToMany(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
@JoinTable(name = "event_userdata",joinColumns={@JoinColumn(name = "eventID")},inverseJoinColumns={@JoinColumn(name = "userID")})
public Collection<UserData> getParticipantsList(){return participantsList;}
public void setParticipantsList(Collection<UserData> participantsList){this.participantsList = participantsList;}
}

@Entity
@Table(name="USERDATA")
public class UserData
{
private long userID;
private String nickname;

@Id
@Column(name="USERID")
@GeneratedValue
public long getUserID(){return userID;}
public void setUserID(long userID){this.userID = userID;}

@Column(name="NICKNAME")
public String getNickname(){return nickname;}
public void setNickname(String nickname){this.nickname = nickname;}
}

Tables in db:
event(eventid)
userdata(userid,nickname)
event_userdata(eventid,userid)


Top
 Profile  
 
 Post subject: Re: HQL help : from Event e join e.participantsList u where u.us
PostPosted: Tue Aug 21, 2012 6:44 am 
Newbie

Joined: Mon Aug 20, 2012 10:37 am
Posts: 2
solution
HQL : select e from Event as e,UserData as u where u.userID=:fuserid


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

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.