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!
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.