Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve collections using projections

 
Ravindranathan Shreeja
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Organization table(id,name,street,city...),Role table(id,description) and a relation table organization-roles

(organizationId,roleId).I would like to get a list of distinct organizations and the roles played by each organization.
My criteria api is as below.

Criteria criteria = hiSession.createCriteria(Organization.class)
.createAlias("organizationRoleses", "organizationRoleses");

List list = criteria.setProjection(Projections.distinct(Projections.projectionList().
add(Projections.property("id"), "id")
.add(Projections.property("name"), "name")
.add(Projections.property("street"), "street")
.add(Projections.property("city"), "city")
.add(Projections.property("organizationRoleses"), "organizationRoleses")
)).setResultTransformer(Transformers.aliasToBean(Organization.class)).list();

In the Organization class I have

public class Organization() {
private int id;
.
.
.
.
private Set organizationRoleses = new HashSet();
}


The problem with this is that 'organizationRoleses' set is not populated.its always null.Is it possible to populate a

collection using projections?
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This link seem to suggest some solutions.
You can try it and post back.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic