Hi,
I'm working with last Hibernate version and I have the topic problem in a many to many relationship. My system's specs are the following:
Hibernate version: 3.2.6
Mapping documents: The main mapping documents here are CANDIDATO and SECCION:
<hibernate-mapping package="entidades">
<class name="Candidato" table="CANDIDATO" schema="USUARIO">
<id name="id" type="long" column="ID_CANDIDATO">
<generator class="native"/>
</id>
[...]
<set name="preferenciasSeccionTecnico" table="TECNI_SECCION" lazy="false">
<key column="ID_CANDIDATO" />
<many-to-many class="SectorTienda" column="ID_SECCION" />
</set>
[...]
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="es.delogica.inditex.entidades" >
<class name="SectorTienda" table="SECCION" schema="USUARIO">
<id name="id" type="integer" column="ID_SECCION">
<generator class="native"/>
</id>
<property name="id_descripcion" column="DESCRIPCION"/>
<property name="abreviatura" column="ABREVIATURA"/>
</class>
</hibernate-mapping>
The Java class are the following:
public class Candidato
{
public Candidato () { }
private Long id;
private Set preferenciasSeccionTecnico;
[...]
public Set getPreferenciasSeccionTecnico() {
return preferenciasSeccionTecnico;
}
public void setPreferenciasSeccionTecnico(Set preferenciasSeccionTecnico) {
this.preferenciasSeccionTecnico = preferenciasSeccionTecnico;
}
}
Code between sessionFactory.openSession() and session.close():
getHibernateTemplate().find("from Candidato");
Full stack trace of any exception that occurs:
org.springframework.dao.InvalidDataAccessResourceUsageException : could not initialize a collection: [es.delogica.inditex.entidades.Candidato.preferenciasSeccionTecnico#1]; nested exception is org.hibernate.exception.SQLGrammarException: could not initialize a collection: [es.delogica.inditex.entidades.Candidato.preferenciasSeccionTecnico#1]
Name and version of the database you are using: DB2 v9.1.200.166
The generated SQL (show_sql=true):
Hibernate:
select
this_.ID_CANDIDATO as ID1_3_0_,
this_.NOMBRE as NOMBRE3_0_,
this_.APELLIDO1 as APELLIDO3_3_0_,
this_.APELLIDO2 as APELLIDO4_3_0_,
this_.TLF_FIJO as TLF5_3_0_,
this_.TLF_MOVIL as TLF6_3_0_,
this_.DNI as DNI3_0_,
this_.COD_POSTAL as COD8_3_0_,
this_.EMAIL as EMAIL3_0_,
this_.NUM_CUENTA as NUM10_3_0_,
this_.NUM_SS as NUM11_3_0_,
this_.LOCALIDAD as LOCALIDAD3_0_,
this_.LOCALIZADO as LOCALIZADO3_0_,
this_.PERMISO_TRAB as PERMISO14_3_0_,
this_.GRADUADO as GRADUADO3_0_,
this_.TARJ_SS as TARJ16_3_0_,
this_.VIDA_LAB as VIDA17_3_0_,
this_.FOTOC_DNI as FOTOC18_3_0_,
this_.DEMANDA_EMP as DEMANDA19_3_0_,
this_.LIBRO_FAM as LIBRO20_3_0_,
this_.CONS_PATERNO as CONS21_3_0_,
this_.EXPERIENCIA_EXT as EXPERIE22_3_0_,
this_.EXPERIENCIA_INT as EXPERIE23_3_0_,
this_.FORMACION_CAJA as FORMACION24_3_0_,
this_.FORMACION_RIESGO as FORMACION25_3_0_,
this_.CONTRATO_FIRMADO as CONTRATO26_3_0_,
this_.MESES_EXT as MESES27_3_0_,
this_.PUESTO_EXT as PUESTO28_3_0_,
this_.TIENDA_EXT as TIENDA29_3_0_,
this_.FEC_DESDE_INT as FEC30_3_0_,
this_.FEC_HASTA_INT as FEC31_3_0_,
this_.REFERENCIANTE_INT as REFEREN32_3_0_,
this_.OBSERVACIONES_INT as OBSERVA33_3_0_,
this_.ID_CADENA_EXP_INT as ID34_3_0_,
this_.ID_MOTIVO_BAJA as ID35_3_0_,
this_.ID_INFORME_INT as ID36_3_0_,
this_.ID_NACIONALIDAD as ID37_3_0_,
this_.ID_PROVINCIA as ID38_3_0_,
this_.ID_CANAL as ID39_3_0_,
this_.ID_BOLSA_TRABAJO as ID40_3_0_,
this_.ID_SEXO as ID41_3_0_,
this_.ID_ESTADO as ID42_3_0_,
this_.ID_VALORACION as ID43_3_0_,
this_.FECHA_NAC as FECHA44_3_0_,
this_.FEC_INCORP_INI as FEC45_3_0_,
this_.FEC_INCORP_FIN as FEC46_3_0_,
this_.FEC_CREACION as FEC47_3_0_,
this_.FEC_MODIFICACION as FEC48_3_0_
from
USUARIO.CANDIDATO this_
Hibernate:
select
preferenci0_.ID_CANDIDATO as ID1_1_,
preferenci0_.ID_SECCION as ID2_1_,
sectortien1_.ID_SECCION as ID1_36_0_,
sectortien1_.DESCRIPCION as DESCRIPC2_36_0_,
sectortien1_.ABREVIATURA as ABREVIAT3_36_0_,
sectortien1_.ID_TIPO_SECCION as ID4_36_0_
from
TECNI_SECCION preferenci0_
left outer join
USUARIO.SECCION sectortien1_
on preferenci0_.ID_SECCION=sectortien1_.ID_SECCION
where
preferenci0_.ID_CANDIDATO=?
The crazy thing is when I copy and paste the generated SQL in DB2 works perfectly!! What the hell is going on?
Thanks in advance.
|