tags:

views:

34

answers:

0

Hi

Say I have an entity that looks like this:

class Person{

long id;

List<String> names;

}

the names collection is a property (not a relation)

Is there a way to query for the names using projections?

first attempt:

sessionFactory.getCurrentSession()
  .createCriteria(Person.class)
  .setProjection(Projections.projectionList()
  .add(Projections.property("id"))
  .add(Projections.property("names")))
  .list();

this gets ids on the first column and null values on the second column.

second attempt:

sessionFactory.getCurrentSession()
  .createCriteria(Person.class)
  .createAlias("names")
  .setProjection(Projections.projectionList()
  .add(Projections.property("id"))
  .add(Projections.property("names")))
  .list();

this generates the Exception:

org.hibernate.MappingException: collection was not an association

what am I doing wrong?