0

我正在尝试创建一些别名来建立一个标准来搜索许多子类的属性。这是我的模型:

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;  
}

我正在尝试为 Person 和 Organization 创建一些别名,如下所示:

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

但我收到一个错误:

Couldn't resolve property person for Entity

任何帮助解决这个问题?我只想知道如何创建别名来引用子类以访问子类属性。

谢谢!

4

1 回答 1

0

我不明白你为什么要在这里使用别名。以下应该足够了:

Criteria criteria = session.createCriteria(Organization.class);
criteria = criteria.add(Restrictions.eq("jobTitle", "XYZ"));
List<Organization> organizations = (List<Organization>) criteria.list();
于 2013-02-18T16:48:28.300 回答