-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate error: could not initialize a collection
PostPosted: Thu Mar 13, 2008 10:30 am 
Newbie

Joined: Thu Mar 13, 2008 9:51 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: Hibernate error: could not initialize a collection
PostPosted: Thu Mar 13, 2008 12:02 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What is the whole stack trace?



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 3:47 am 
Newbie

Joined: Thu Mar 13, 2008 9:51 am
Posts: 2
I haven't the whole stack trace, I don't know why Tomcat is not printing it to the console, but I have the error received in the app layer and says:

Server.Processing
DescripciĆ³n: could not initialize a collection: [es.delogica.inditex.entidades.Tienda.secciones#1002]
faultCode:Server.Processing faultString:'could not initialize a collection: [es.delogica.inditex.entidades.Tienda.secciones#1002]

But I have a clue, I have tried to init Tomcat with update mode and it tries to update the schema with this:

org.hibernate.tool.hbm2ddl.SchemaUpdate execute
GRAVE: Unsuccessful: alter table TECNI_SECCION add constraint FK30619364FBA272E4 foreign key (ID_CANDIDATO) references USUARIO.CANDIDATO

I don't know why Tomcat tries to update the schema with this because I create this foreign key when I create the database:
alter table TECNI_SECCION
add constraint FK_TECNI_SECC_CAND foreign key (ID_CANDIDATO)
references CANDIDATO (ID_CANDIDATO)
on delete restrict on update restrict;

And I think is the same constraint, what's wrong here?

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 9:38 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Do you have hibernate.hbm2ddl.auto in your hibernate config file?


Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.