我有一个在运行时安装的字段,就像另一个字段的联接。看:
public String getNumeroCip() {
if (this.getId() == null) {
return "BR0000000000000";
}
String idFormated = String.format("%011d", this.getId());
return "BR" + idFormated + this.produto.getProduto().getSufixo();
}
这是我的字段,在运行时安装。我可以称其为:bean.numeroCip。
但是如果我尝试在 HQL 中使用它,如下所示:
@NamedQuery(name = "Ar.findByNumeroArOrCip", query = "SELECT c FROM AR c "
+ "JOIN FETCH c.produto "
+ "JOIN FETCH c.situacao "
+ "WHERE c.numeroAr = :numeroAr OR c.numeroCip = :numeroCip")
当我尝试启动 tomcat 服务器时出现以下错误:
Caused by: org.hibernate.HibernateException: Errors in named queries: Ar.findByNumeroArOrCip
最佳答案
临时字段不能在 HQL 查询中使用。最后,HQL 查询被转换为 SQL 查询,然后针对数据库执行。数据库不知道 Java 对象的字段。
关于java - 在 HQL 中使用 transient 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20597930/