0

I am trying to create some aliases to build a criteria to search by properties of many subclasses. Here is my model:

public abstract class Entity {

protected int id;
protected PartyBasicGroup partyBasicGroup;

}

public class Person extends Entity {

}

public class Organization extends Entity {

protected PartyBasicGroup signatoryBasicGroup;
protected String jobTitle;  
}

I am trying to create some aliases for Person and Organization as follows:

criteria = criteria.createAlias("entity.person", "person", JoinType.LEFT_OUTER_JOIN);
criteria = criteria.createAlias("entity.organization", "organization", JoinType.LEFT_OUTER_JOIN);

But I'm getting an error:

Couldn't resolve property person for Entity

Any help to fix this issue? I just wanna know how to create aliases to reference subclasses in order to access subclasses properties.

Thanks!

  • 2
    What is the final query you are trying to execute here ? Because "entity.person" and "entity.organization" has no meaning, Person and Organization are subclasses of Entity, not properties ! – overmeulen Feb 18 '13 at 15:45
  • I'm trying to search specific jobTitles but I don't know how to create the alias to access the properties of Organization. I know there are subclasses, but I have seen in another codes that Hibernate lets deal with them as properties. – user2083783 Feb 18 '13 at 16:39

1 Answers1

0

I don't understand why you want to use aliases here. The following should be enough :

Criteria criteria = session.createCriteria(Organization.class);
criteria = criteria.add(Restrictions.eq("jobTitle", "XYZ"));
List<Organization> organizations = (List<Organization>) criteria.list();
overmeulen
  • 1,158
  • 6
  • 15