-->
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.  [ 2 posts ] 
Author Message
 Post subject: Subquery problem
PostPosted: Mon Nov 23, 2009 7:11 pm 
Newbie

Joined: Mon Nov 23, 2009 6:59 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Subquery problem
PostPosted: Mon Nov 23, 2009 7:19 pm 
Newbie

Joined: Mon Nov 23, 2009 6:59 pm
Posts: 2
Other info, if I run this:
Code:
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();

or this:
Code:
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()));
           
            cr = session.createCriteria(GoUser.class, "User");
            cr.add(Subqueries.exists(dcr2));
            res = cr.list();

Then I get correct results and everything is fine, so I suggest that everything is mapped correctly and all needed fields are in...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.