简体   繁体   English

在HQL中使用瞬态场

[英]Using a transient field in HQL

I have a field this is mounted in run-time, like a join of another fields. 我有一个在运行时安装的字段,就像另一个字段的联接一样。 Look: 看:

public String getNumeroCip() {

        if (this.getId() == null) {
            return "BR0000000000000";
        }

        String idFormated = String.format("%011d", this.getId());
        return "BR" + idFormated + this.produto.getProduto().getSufixo();
    }

This is my field, mounted in run-time. 这是我的领域,在运行时安装。 I can call it doing: bean.numeroCip. 我可以这样称呼它:bean.numeroCip。

But if i try use this in a HQL, like this: 但是,如果我尝试在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")

I got the following error when i try start tomcat server: 尝试启动tomcat服务器时出现以下错误:

Caused by: org.hibernate.HibernateException: Errors in named queries: Ar.findByNumeroArOrCip

Transient fields cannot be used in HQL queries. HQL查询中不能使用瞬态字段。 In the end HQL query is translated to the SQL query, which is then executed against database. 最后,将HQL查询转换为SQL查询,然后针对数据库执行该查询。 Database is not aware of fields of Java objects. 数据库不知道Java对象的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM