-->
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.  [ 1 post ] 
Author Message
 Post subject: one-to-one mapping relation problem
PostPosted: Tue Jan 09, 2007 10:24 am 
Newbie

Joined: Fri Oct 14, 2005 6:22 am
Posts: 7
Hi, i want to map a one-to-one relation between the tables User and Employee, and other one-to-one relation between the tables User and WebUser.

When i get a User object, the select that Hibernate does involve the two tables, Employee and UserWeb, and i am interesting in when the id_tipo_usuario column of the User table is "0", the select that Hibernate does involve the table Employee, and when the id_tipo_usuario column of the User table is "1", the select that Hibernate does involve the table UserWeb.

Any idea about how do it?

Hibernate version: 3.1

Mapping documents:

User.hbm.xml

<hibernate-mapping>
<class name="com.itdeusto.itdknowledge.model.UsuarioDto" table="ITDK_USUARIO">
<id name="id" type="java.lang.String" unsaved-value="null">
<column name="ID" length="32" />
<generator class="uuid.hex" />
</id>

<discriminator
type="string">
<formula>
case
when id_tipo_usuario='0' then 'E'
when id_tipo_usuario='1' then 'UW'
else 'P'
end
</formula>
</discriminator>

<version name="version" />

<many-to-one name="id_tipo_usuario" class="com.itdeusto.itdknowledge.model.TipoUsuarioDto" fetch="join">
<column name="ID_TIPO_USUARIO" length="32" not-null="true" />
</many-to-one>

<one-to-one name="empleado" class="com.itdeusto.itdknowledge.model.EmpleadoDto" cascade="all" />

<one-to-one name="usuarioWeb" class="com.itdeusto.itdknowledge.model.UsuarioWebDto" cascade="all" />

<set name="perfiles" table="ITDK_USUARIO_PERFIL" inverse="false" lazy="true" cascade="all-delete-orphan">
<key column="ID_USUARIO" />
<many-to-many column="ID_PERFIL" class="com.itdeusto.itdknowledge.model.PerfilDto" />
</set>

<set name="certificaciones" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.CertificacionEmpDto"/>
</set>

<set name="conocimientos" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.ConocimientoEmpDto"/>
</set>

<set name="cursos" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.CursoEmpDto"/>
</set>

<set name="experienciasAnt" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="fec_inicio,fec_fin,id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.ExperienciaAntDto"/>
</set>

<set name="experienciasItd" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="fec_inicio,fec_fin,id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.ExperienciaItdDto"/>
</set>

<set name="idiomas" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.IdiomaEmpDto"/>
</set>

<set name="masters" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.MasterEmpDto"/>
</set>

<set name="titulaciones" cascade="all-delete-orphan" inverse="true" lazy="true" order-by="id">
<key column="ID_USUARIO" />
<one-to-many class="com.itdeusto.itdknowledge.model.TitulacionEmpDto"/>
</set>
</class>
</hibernate-mapping>

Employee.hbm.xml

<hibernate-mapping>
<class name="com.itdeusto.itdknowledge.model.EmpleadoDto" table="ITDK_EMPLEADO" discriminator-value="E">
<id name="id" type="java.lang.String" unsaved-value="null">
<column name="ID" length="32" />
<generator class="foreign">
<param name="property">usuario</param>
</generator>
</id>

<version name="version" />

<one-to-one name="usuario" class="com.itdeusto.itdknowledge.model.UsuarioDto" constrained="true" />

<many-to-one name="id_estado_emp" class="com.itdeusto.itdknowledge.model.EstadoEmpDto" fetch="join">
<column name="ID_ESTADO_EMP" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_zona" class="com.itdeusto.itdknowledge.model.ZonaDto" fetch="join">
<column name="ID_ZONA" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_pais" class="com.itdeusto.itdknowledge.model.PaisDto" fetch="join">
<column name="ID_PAIS" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_localidad" class="com.itdeusto.itdknowledge.model.LocalidadDto" fetch="join">
<column name="ID_LOCALIDAD" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_delegacion" class="com.itdeusto.itdknowledge.model.DelegacionDto" fetch="join">
<column name="ID_DELEGACION" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_genero" class="com.itdeusto.itdknowledge.model.GeneroDto" fetch="join">
<column name="ID_GENERO" length="32" />
</many-to-one>
<many-to-one name="id_lineaservicio" class="com.itdeusto.itdknowledge.model.LineaServicioDto" fetch="join">
<column name="ID_LINEA_SERVICIO" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_provincia" class="com.itdeusto.itdknowledge.model.ProvinciaDto" fetch="join">
<column name="ID_PROVINCIA" length="32" not-null="true" />
</many-to-one>

<property name="login" type="java.lang.String">
<column name="LOGIN" not-null="true" unique="true" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="flgBloqueado" type="java.lang.String">
<column name="FLG_BLOQUEADO" not-null="true" />
</property>
<property name="nombre" type="java.lang.String">
<column name="NOMBRE" length="100" not-null="true" />
</property>
<property name="ape1" type="java.lang.String">
<column name="APE1" length="100" not-null="true" />
</property>
<property name="ape2" type="java.lang.String">
<column name="APE2" length="100" not-null="true" />
</property>
<property name="nif" type="java.lang.String">
<column name="NIF" length="10" not-null="true" unique="true" />
</property>
<property name="codItd" type="java.lang.String">
<column name="COD_ITD" length="32" unique="true" />
</property>
<property name="foto" type="java.lang.String">
<column name="FOTO" length="100" />
</property>
<property name="fecNacimiento" type="java.util.Date">
<column name="FEC_NACIMIENTO" length="7" not-null="true" />
</property>
<property name="direccion" type="java.lang.String">
<column name="DIRECCION" not-null="true" />
</property>
<property name="codPostal" type="java.lang.String">
<column name="COD_POSTAL" length="5" />
</property>
<property name="tel1" type="java.lang.String">
<column name="TEL_1" length="13" not-null="true" />
</property>
<property name="tel2" type="java.lang.String">
<column name="TEL_2" length="13" />
</property>
<property name="email1" type="java.lang.String">
<column name="EMAIL1" length="100" not-null="true" />
</property>
<property name="email2" type="java.lang.String">
<column name="EMAIL2" length="100" />
</property>
<property name="aniosExperiencia" type="java.lang.Integer">
<column name="ANIOS_EXPERIENCIA" precision="22" scale="0" />
</property>
<property name="fecAltaItd" type="java.util.Date">
<column name="FEC_ALTA_ITD" length="7" not-null="true" />
</property>
<property name="fecBajaItd" type="java.util.Date">
<column name="FEC_BAJA_ITD" length="7" />
</property>
<property name="categoriaContrato" type="java.lang.String">
<column name="CATEGORIA_CONTRATO" length="100" />
</property>
<property name="puestoItd" type="java.lang.String">
<column name="PUESTO_ITD" length="100" />
</property>
<property name="costeHora" type="java.lang.Double">
<column name="COSTE_HORA" precision="2" />
</property>
<property name="salario" type="java.lang.Double">
<column name="SALARIO" precision="10" />
</property>
<property name="variable" type="java.lang.Double">
<column name="VARIABLE" precision="10" />
</property>
<property name="idJornada" type="java.lang.String">
<column name="ID_JORNADA" length="32" />
</property>
<property name="idContrato" type="java.lang.String">
<column name="ID_CONTRATO" length="32" />
</property>

</class>
</hibernate-mapping>

WebUser.hbm.xml

<hibernate-mapping>
<class name="com.itdeusto.itdknowledge.model.UsuarioWebDto" table="ITDK_USUARIO_WEB" discriminator-value="UW">
<id name="id" type="java.lang.String" unsaved-value="null">
<column name="ID" length="32" />
<generator class="foreign">
<param name="property">usuario</param>
</generator>
</id>

<version name="version" />

<one-to-one name="usuario" class="com.itdeusto.itdknowledge.model.UsuarioDto" constrained="true" />

<many-to-one name="id_pais" class="com.itdeusto.itdknowledge.model.PaisDto" fetch="join">
<column name="ID_PAIS" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_localidad" class="com.itdeusto.itdknowledge.model.LocalidadDto" fetch="join">
<column name="ID_LOCALIDAD" length="32" not-null="true" />
</many-to-one>
<many-to-one name="id_genero" class="com.itdeusto.itdknowledge.model.GeneroDto" fetch="join">
<column name="ID_GENERO" length="32" />
</many-to-one>
<many-to-one name="id_provincia" class="com.itdeusto.itdknowledge.model.ProvinciaDto" fetch="join">
<column name="ID_PROVINCIA" length="32" not-null="true" />
</many-to-one>

<property name="login" type="java.lang.String">
<column name="LOGIN" not-null="true" unique="true" />
</property>
<property name="password" type="java.lang.String">
<column name="PASSWORD" />
</property>
<property name="nombre" type="java.lang.String">
<column name="NOMBRE" length="100" not-null="true" />
</property>
<property name="ape1" type="java.lang.String">
<column name="APE1" length="100" not-null="true" />
</property>
<property name="ape2" type="java.lang.String">
<column name="APE2" length="100" not-null="true" />
</property>
<property name="nif" type="java.lang.String">
<column name="NIF" length="10" not-null="true" unique="true" />
</property>
<property name="foto" type="java.lang.String">
<column name="FOTO" length="100" />
</property>
<property name="curriculumAdjunto" type="java.lang.String">
<column name="CURRICULUM_ADJUNTO" length="100" />
</property>
<property name="fecNacimiento" type="java.util.Date">
<column name="FEC_NACIMIENTO" length="7" not-null="true" />
</property>
<property name="direccion" type="java.lang.String">
<column name="DIRECCION" not-null="true" />
</property>
<property name="codPostal" type="java.lang.String">
<column name="COD_POSTAL" length="5" />
</property>
<property name="tel1" type="java.lang.String">
<column name="TEL_1" length="13" not-null="true" />
</property>
<property name="tel2" type="java.lang.String">
<column name="TEL_2" length="13" />
</property>
<property name="email1" type="java.lang.String">
<column name="EMAIL1" length="100" not-null="true" />
</property>
<property name="email2" type="java.lang.String">
<column name="EMAIL2" length="100" />
</property>
<property name="aniosExperiencia" type="java.lang.Integer">
<column name="ANIOS_EXPERIENCIA" precision="22" scale="0" />
</property>

</class>
</hibernate-mapping>





Full stack trace of any exception that occurs:

Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true):
Hibernate: select usuariodto0_.ID as ID17_, usuariodto0_.version as version38_17_, usuariodto0_.ID_TIPO_USUARIO as ID3_38_17_, tipousuari1_.ID as ID0_, tipousuari1_.version as version39_0_, tipousuari1_.DESCRIPCION as DESCRIPC3_39_0_, empleadodt2_.ID as ID1_, empleadodt2_.version as version3_1_, empleadodt2_.ID_ESTADO_EMP as ID3_3_1_, empleadodt2_.ID_ZONA as ID4_3_1_, empleadodt2_.ID_PAIS as ID5_3_1_, empleadodt2_.ID_LOCALIDAD as ID6_3_1_, empleadodt2_.ID_DELEGACION as ID7_3_1_, empleadodt2_.ID_GENERO as ID8_3_1_, empleadodt2_.ID_LINEA_SERVICIO as ID9_3_1_, empleadodt2_.ID_PROVINCIA as ID10_3_1_, empleadodt2_.LOGIN as LOGIN3_1_, empleadodt2_.PASSWORD as PASSWORD3_1_, empleadodt2_.FLG_BLOQUEADO as FLG13_3_1_, empleadodt2_.NOMBRE as NOMBRE3_1_, empleadodt2_.APE1 as APE15_3_1_, empleadodt2_.APE2 as APE16_3_1_, empleadodt2_.NIF as NIF3_1_, empleadodt2_.COD_ITD as COD18_3_1_, empleadodt2_.FOTO as FOTO3_1_, empleadodt2_.FEC_NACIMIENTO as FEC20_3_1_, empleadodt2_.DIRECCION as DIRECCION3_1_, empleadodt2_.COD_POSTAL as COD22_3_1_, empleadodt2_.TEL_1 as TEL23_3_1_, empleadodt2_.TEL_2 as TEL24_3_1_, empleadodt2_.EMAIL1 as EMAIL25_3_1_, empleadodt2_.EMAIL2 as EMAIL26_3_1_, empleadodt2_.ANIOS_EXPERIENCIA as ANIOS27_3_1_, empleadodt2_.FEC_ALTA_ITD as FEC28_3_1_, empleadodt2_.FEC_BAJA_ITD as FEC29_3_1_, empleadodt2_.CATEGORIA_CONTRATO as CATEGORIA30_3_1_, empleadodt2_.PUESTO_ITD as PUESTO31_3_1_, empleadodt2_.COSTE_HORA as COSTE32_3_1_, empleadodt2_.SALARIO as SALARIO3_1_, empleadodt2_.VARIABLE as VARIABLE3_1_, empleadodt2_.ID_JORNADA as ID35_3_1_, empleadodt2_.ID_CONTRATO as ID36_3_1_, estadoempd3_.ID as ID2_, estadoempd3_.version as version4_2_, estadoempd3_.DESCRIPCION as DESCRIPC3_4_2_, zonadto4_.ID as ID3_, zonadto4_.version as version5_3_, zonadto4_.DESCRIPCION as DESCRIPC3_5_3_, paisdto5_.ID as ID4_, paisdto5_.version as version6_4_, paisdto5_.DESCRIPCION as DESCRIPC3_6_4_, localidadd6_.ID as ID5_, localidadd6_.version as version7_5_, localidadd6_.ID_PROVINCIA as ID3_7_5_, localidadd6_.DESCRIPCION as DESCRIPC4_7_5_, provinciad7_.ID as ID6_, provinciad7_.version as version10_6_, provinciad7_.DESCRIPCION as DESCRIPC3_10_6_, delegacion8_.ID as ID7_, delegacion8_.version as version8_7_, delegacion8_.DESCRIPCION as DESCRIPC3_8_7_, delegacion8_.ID_ZONA as ID4_8_7_, zonadto9_.ID as ID8_, zonadto9_.version as version5_8_, zonadto9_.DESCRIPCION as DESCRIPC3_5_8_, generodto10_.ID as ID9_, generodto10_.version as version11_9_, generodto10_.DESCRIPCION as DESCRIPC3_11_9_, lineaservi11_.ID as ID10_, lineaservi11_.version as version9_10_, lineaservi11_.DESCRIPCION as DESCRIPC3_9_10_, provinciad12_.ID as ID11_, provinciad12_.version as version10_11_, provinciad12_.DESCRIPCION as DESCRIPC3_10_11_, usuarioweb13_.ID as ID12_, usuarioweb13_.version as version40_12_, usuarioweb13_.ID_PAIS as ID3_40_12_, usuarioweb13_.ID_LOCALIDAD as ID4_40_12_, usuarioweb13_.ID_GENERO as ID5_40_12_, usuarioweb13_.ID_PROVINCIA as ID6_40_12_, usuarioweb13_.LOGIN as LOGIN40_12_, usuarioweb13_.PASSWORD as PASSWORD40_12_, usuarioweb13_.NOMBRE as NOMBRE40_12_, usuarioweb13_.APE1 as APE10_40_12_, usuarioweb13_.APE2 as APE11_40_12_, usuarioweb13_.NIF as NIF40_12_, usuarioweb13_.FOTO as FOTO40_12_, usuarioweb13_.CURRICULUM_ADJUNTO as CURRICULUM14_40_12_, usuarioweb13_.FEC_NACIMIENTO as FEC15_40_12_, usuarioweb13_.DIRECCION as DIRECCION40_12_, usuarioweb13_.COD_POSTAL as COD17_40_12_, usuarioweb13_.TEL_1 as TEL18_40_12_, usuarioweb13_.TEL_2 as TEL19_40_12_, usuarioweb13_.EMAIL1 as EMAIL20_40_12_, usuarioweb13_.EMAIL2 as EMAIL21_40_12_, usuarioweb13_.ANIOS_EXPERIENCIA as ANIOS22_40_12_, paisdto14_.ID as ID13_, paisdto14_.version as version6_13_, paisdto14_.DESCRIPCION as DESCRIPC3_6_13_, localidadd15_.ID as ID14_, localidadd15_.version as version7_14_, localidadd15_.ID_PROVINCIA as ID3_7_14_, localidadd15_.DESCRIPCION as DESCRIPC4_7_14_, generodto16_.ID as ID15_, generodto16_.version as version11_15_, generodto16_.DESCRIPCION as DESCRIPC3_11_15_, provinciad17_.ID as ID16_, provinciad17_.version as version10_16_, provinciad17_.DESCRIPCION as DESCRIPC3_10_16_ from ITDK_USUARIO usuariodto0_, ITDK_TIPO_USUARIO tipousuari1_, ITDK_EMPLEADO empleadodt2_, ITDK_ESTADO_EMP estadoempd3_, ITDK_ZONA zonadto4_, ITDK_PAIS paisdto5_, ITDK_LOCALIDAD localidadd6_, ITDK_PROVINCIA provinciad7_, ITDK_DELEGACION delegacion8_, ITDK_ZONA zonadto9_, ITDK_GENERO generodto10_, ITDK_LINEA_SERVICIO lineaservi11_, ITDK_PROVINCIA provinciad12_, ITDK_USUARIO_WEB usuarioweb13_, ITDK_PAIS paisdto14_, ITDK_LOCALIDAD localidadd15_, ITDK_GENERO generodto16_, ITDK_PROVINCIA provinciad17_ where usuariodto0_.ID_TIPO_USUARIO=tipousuari1_.ID and usuariodto0_.ID=empleadodt2_.ID(+) and empleadodt2_.ID_ESTADO_EMP=estadoempd3_.ID(+) and empleadodt2_.ID_ZONA=zonadto4_.ID(+) and empleadodt2_.ID_PAIS=paisdto5_.ID(+) and empleadodt2_.ID_LOCALIDAD=localidadd6_.ID(+) and localidadd6_.ID_PROVINCIA=provinciad7_.ID(+) and empleadodt2_.ID_DELEGACION=delegacion8_.ID(+) and delegacion8_.ID_ZONA=zonadto9_.ID(+) and empleadodt2_.ID_GENERO=generodto10_.ID(+) and empleadodt2_.ID_LINEA_SERVICIO=lineaservi11_.ID(+) and empleadodt2_.ID_PROVINCIA=provinciad12_.ID(+) and usuariodto0_.ID=usuarioweb13_.ID(+) and usuarioweb13_.ID_PAIS=paisdto14_.ID(+) and usuarioweb13_.ID_LOCALIDAD=localidadd15_.ID(+) and usuarioweb13_.ID_GENERO=generodto16_.ID(+) and usuarioweb13_.ID_PROVINCIA=provinciad17_.ID(+) and usuariodto0_.ID=?


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

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.