Question

I need to fetch selected columns of a table from database through hibernate criteria , I have already got the pojo corresponding to the table and it mapping is done , i am writing the criteria in the below format but it is not working fine as upon debuging and inspecting i can see that the list is empty please advise what is wroing in the below quoery

public List<abc> Extractingioapublishfor()
        {
            Criteria criteria = session.createCriteria(abc.class);

            criteria.setProjection( Projections.projectionList().add(Projections.property("rId;")));
            criteria.setProjection( Projections.projectionList().add(Projections.property("tId")));
            criteria.setProjection( Projections.projectionList().add(Projections.property("ld")));
            return criteria.list();
        }
Was it helpful?

Solution

Firstly, there is a ';' in the first column name. That might be the reason it is not getting results. Secondly, all projections should be added to the same projection list like below;

public List<abc> Extractingioapublishfor()
        {
            Criteria criteria = session.createCriteria(abc.class);

            criteria.setProjection( Projections.projectionList().add(Projections.property("rId"))
 .add(Projections.property("tId")).add(Projections.property("ld")));
            return criteria.list();
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top