Im getting this error, im trying to access a child property using one-to-many relation in hibernate:
org.hibernate.QueryException: illegal attempt to dereference collection [sigtccontr0_.ID_OBJETIVO.children] with element property reference [idIniciativa] [from org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaObjetivos p where p.children.idIniciativa = 1]
This is my query:
String sql = "from SigTcContraloriaObjetivos p where p.children.idIniciativa = 1";
Dto ´s:
public class SigTcContraloriaObjetivos {
private Long idObjetivo;
private String descripcion;
private Set<SigTcContraloriaIniciativas> children;
public class SigTcContraloriaIniciativas {
private Long idIniciativa;
private String descripcion;
private Long idObjetivo;
Mappings:
<class dynamic-insert="false" dynamic-update="true" mutable="true"
name="org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaObjetivos"
optimistic-lock="version" polymorphism="implicit" select-before-update="false"
table="SIG_TC_CONTRALORIA_OBJETIVOS">
<id column="ID_OBJETIVO" name="idObjetivo">
<generator class="sequence">
<param name="sequence">SEQ_SIG_CONTRALORIA_OBJETIVOS</param>
</generator>
</id>
<property column="DESCRIPCION" name="descripcion"/>
<set name="children" inverse="false" cascade="all" lazy="false">
<key column="ID_OBJETIVO"/>
<one-to-many class="SigTcContraloriaIniciativas"/>
</set>
</class>
<class dynamic-insert="false" dynamic-update="true" mutable="true" name="org.citi.tablero.contraloria.planes.model.db.hibernate.dto.SigTcContraloriaIniciativas"
optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="SIG_TC_CONTRALORIA_INICIATIVAS">
<id column="ID_INICIATIVA" name="idIniciativa">
<generator class="sequence">
<param name="sequence">SEQ_SIG_CONTRALORIA_INICIATIVA</param>
</generator>
</id>
<property column="DESCRIPCION" name="descripcion"/>
<property column="ID_OBJETIVO" name="idObjetivo" />
</class>
Any idea how to access to idIniciativa
?
Update: when using the query provided: "select p from SigTcContraloriaObjetivos p join p.children c where c.idIniciativa = 1"
query.list() returns:
Object1:
Object2:
And i need:
You cannot access a collection that way with Hibernate. Something like the following should work:
select p from SigTcContraloriaObjetivos p join p.children c where c.idIniciativa = 1
See here for more info: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-joins
Note, this is for Hibernate 3.3.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.