Monday, July 27, 2009

Hibernate : how to get the data from many to many relation tables

Hibernate : how to get the data from many to many relation tables :

Query : select project from Project as project join project.users user where user.userID=:userId


Example:

List projectList =(ArrayList)getHibernateTemplate().execute(new HibernateCallback(){
@Override
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String lHql="select project from Project as project join project.users user where user.userID=:userId";
Query lQuery=session.createQuery(lHql);
lQuery.setLong("userId", pUserId);
List lProject=lQuery.list();
return lProject;
}
});

No comments: