我想在 HQL 中使用我的“where”子句中的抽象方法的结果。这可以做到吗?
像这样的东西:
@NamedQuery(name="getMailRelations", query="Select mr from MailRelation mr where mr.getOccurrences() > 5"
我有一个像这样的映射超类
@Entity
@Table(name="Mail_Entity", schema="relations")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="relationType", discriminatorType=DiscriminatorType.STRING)
@PersistenceContext(name="domas")
public abstract class MailRelation {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST})
@JoinColumn(name="mailId", referencedColumnName="mailId", nullable=false)
private Mail mail;
public void setMail(Mail mail) {
this.mail = mail;
if(!mail.getMailRelations().contains(this))
mail.addMailRelation(this);
}
public abstract int getOccurrences();
public Mail getMail() {
return mail;
// and more code......