Java 将基于联接的聚合查询的结果映射到Hibernate属性

Java 将基于联接的聚合查询的结果映射到Hibernate属性,java,sql,hibernate,hql,Java,Sql,Hibernate,Hql,我需要得到聚合函数到实体属性的结果。我尝试使用Hibernate的@Formula Anotion,但她显然对连接有问题。有没有其他方法可以将这些查询的结果转化为对象属性 简化数据模型 值nandoCode.id和auditor.id是此对象的属性 感谢您的建议首先,此查询范围中没有nanoCode.id或auditor.id这类内容 如果您试图访问AuditorAndocode注释中@Formula内的AuditorAndocode.auditor.id,您应该只使用列名——在本例中,可能是a

我需要得到聚合函数到实体属性的结果。我尝试使用Hibernate的@Formula Anotion,但她显然对连接有问题。有没有其他方法可以将这些查询的结果转化为对象属性

简化数据模型

值nandoCode.id和auditor.id是此对象的属性


感谢您的建议

首先,此查询范围中没有nanoCode.id或auditor.id这类内容

如果您试图访问AuditorAndocode注释中@Formula内的AuditorAndocode.auditor.id,您应该只使用列名——在本例中,可能是auditor\u id

因此,请尝试以下注释:

@Formula(value = "(select COALESCE(sum(anc.category_specific_training),0) from quasar_auditor_has_nando_code anc "+
                     "inner join quasar_nando_code nc ON anc.nando_code_id=nc.id "+
                     "where nc.parent_id = nandoCode_id and anc.auditor_id = auditor_id)")
@Formula(value = "(select COALESCE(sum(anc.category_specific_training),0) from quasar_auditor_has_nando_code anc "+
                     "inner join quasar_nando_code nc ON anc.nando_code_id=nc.id "+
                     "where nc.parent_id = nandoCode_id and anc.auditor_id = auditor_id)")