Hello
Here are tables I have in database: User => TeamParticipate <= Team => Participate <= SubProject <= Project
I need to get list of users who are in teams that participate in subproject which is in certain project.
But when I'm trying to do this:
Code:
public List<GoUser> getUsers(int p_id)
{
Session session = sessionFactory.openSession();
Criteria cr;
List<GoUser> res = new ArrayList<GoUser>();
if (p_id>0)
{
GoProject pr = (GoProject) session.load(TComponents.GoProject.class, p_id);
DetachedCriteria dcr1 = DetachedCriteria.forClass(GoParticipate.class, "Participate");
ProjectionList l = Projections.projectionList()
.add(Projections.property("Participate.goTeam.tMId"))
.add(Projections.property("Participate.goSubproject.sPRGId"));
dcr1.setProjection(l);
dcr1.add(Property.forName("Participate.goTeam.tMId").eqProperty("TeamParticipate.goTeam.tMId"));
dcr1.add(Property.forName("Participate.goSubproject").in(pr.getGoSubprojectList()));
DetachedCriteria dcr2 = DetachedCriteria.forClass(GoTeamparticipate.class, "TeamParticipate");
dcr2.setProjection(Projections.property("TeamParticipate.goTeam.tMId"));
dcr2.add(Property.forName("TeamParticipate.goUser.uSRId").eqProperty("User.uSRId"));
dcr2.add(Subqueries.exists(dcr1));
cr = session.createCriteria(GoUser.class, "User");
cr.add(Subqueries.exists(dcr2));
res = cr.list();
} else
{
cr = session.createCriteria(TComponents.GoUser.class);
res = cr.list();
}
return res;
}
I get :
java.lang.NullPointerException
at org.hibernate.criterion.SubqueryExpression.getTypedValues(SubqueryExpression.java:80)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:251)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:55)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
...
Can anyone suggest what's wrong I'm doing here?
Thx