-->
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.  [ 1 post ] 
Author Message
 Post subject: Projection of Collection field supported?
PostPosted: Mon Feb 13, 2012 6:40 pm 
Newbie

Joined: Mon Feb 13, 2012 6:37 pm
Posts: 2
Say I have a class Entity with a field myCollection that is a List or other type of Collection. When I load instances of Entity via Hibernate, the myCollection field is populated correctly. However, if I do a Criteria query and I have a property projection for the myCollection field, the data returned (List<Object[]>) always contains a null corresponding to myCollection in each row, e.g. ([1, null], [2, null], ...). Does Hibernate support doing this type of projection on a field that is a Collection?

Code:
class Entity {
  public Long id;
  public List<String> myCollection;
}

Criteria cr = getCurrentSession().createCriteria(Entity.class)
  .setProjection(Projections.projectionList()
    .add(Property.forName("id"))
    .add(Property.forName("myCollection"))
  );


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.