-->
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: Joined secondary select
PostPosted: Mon Jun 04, 2007 2:12 pm 
Newbie

Joined: Wed Oct 06, 2004 4:39 pm
Posts: 17
Hibernate version:
3.2.3

Mapping documents:
@Entity
@Table(name = "bien")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Bien extends AbstractPOJO {

....
protected Ubicacion ubicacionPorDefecto;
protected UnidadMedida unidadMedida;

....
@ManyToOne
@JoinColumn(name = "id_ubicacionpordefecto")
@org.hibernate.annotations.ForeignKey(name = "fk_bien_ubicacion")
public Ubicacion getUbicacionPorDefecto() {
return ubicacionPorDefecto;
}

@ManyToOne
@JoinColumn(name = "id_unidadmedida", nullable = false)
@org.hibernate.annotations.ForeignKey(name = "fk_bien_unidadmedida")
public UnidadMedida getUnidadMedida() {
return unidadMedida;
}
}


@Entity
@Table(name = "material")
@PrimaryKeyJoinColumn(name = "id_material")
public abstract class Material extends Bien {
...
}

@Entity
@Table(name = "materia_prima")
@PrimaryKeyJoinColumn(name = "id_materiaprima")
public class MateriaPrimaextends Material {
...
}

@Entity
@Table(name = "material_acondicionamiento")
@PrimaryKeyJoinColumn(name = "id_materialacondicionamiento")
public class MaterialAcondicionamiento extends Material {

....
private CategoriaEnvase categoriaEnvase;
....

@ManyToOne
@JoinColumn(name = "id_categoriaenvase", nullable = false)
@org.hibernate.annotations.ForeignKey(name = "fk_materialacondicionamiento_categoriaenvase")
public CategoriaEnvase getCategoriaEnvase() {
return categoriaEnvase;
}
}

I have:

Bien
..|-->Material
.........|-->MateriaPrima
.........|-->MaterialAcondicionamiento

I need retrieve instances of Material. I use the query:
"select m from Material m left join fetch m.ubicacionPorDefecto join fetch m.unidadMedida"

This generate the sql:
select
material0_.id_material as id3_0_,
ubicacion1_.id as id77_1_,
unidadmedi3_.id as id78_3_,
material0_1_.codigo as codigo3_0_,
material0_1_.costopromediomonto as costopro3_3_0_,
material0_1_.costopromediomoneda as costopro4_3_0_,
material0_1_.detalle as detalle3_0_,
material0_1_.discriminador as discrimi6_3_0_,
material0_1_.frecuenciaconteo as frecuenc7_3_0_,
material0_1_.nombre as nombre3_0_,
material0_1_.toleranciaconteo as toleranc9_3_0_,
material0_1_.id_ubicacionpordefecto as id11_3_0_,
material0_1_.id_unidadmedida as id12_3_0_,
material0_1_.version as version3_0_,
material0_.cantidadcomprometida as cantidad2_54_0_,
material0_.cantidadfaltante as cantidad3_54_0_,
material0_.cantidadordenada as cantidad4_54_0_,
material0_.tiempoaprovisionamiento as tiempoap5_54_0_,
material0_3_.extensionvalidez as extensio2_56_0_,
material0_3_.tipo as tipo56_0_,
material0_4_.cantidadenacondicionamiento as cantidad2_57_0_,
material0_4_.id_categoriaenvase as id3_57_0_,
case
when material0_3_.id_materiaprima is not null then 3
when material0_4_.id_materialacondicionamiento is not null then 4
when material0_2_.id_materialconestado is not null then 2
when material0_.id_material is not null then 1
end as clazz_0_,
ubicacion1_.activa as activa77_1_,
ubicacion1_.detalle as detalle77_1_,
ubicacion1_.entregar as entregar77_1_,
ubicacion1_.nombre as nombre77_1_,
ubicacion1_.recibir as recibir77_1_,
ubicacion1_.id_tipoubicacion as id8_77_1_,
ubicacion1_.version as version77_1_,
unidadmedi3_.abreviatura as abreviat2_78_3_,
unidadmedi3_.detalle as detalle78_3_,
unidadmedi3_.nombre as nombre78_3_,
unidadmedi3_.tipo as tipo78_3_,
unidadmedi3_.version as version78_3_
from
material material0_
inner join
bien material0_1_
on material0_.id_material=material0_1_.id
left outer join
materia_prima material0_3_
on material0_.id_material=material0_3_.id_materiaprima
left outer join
material_acondicionamiento material0_4_
on material0_.id_material=material0_4_.id_materialacondicionamiento
left outer join
ubicacion ubicacion1_
on material0_1_.id_ubicacionpordefecto=ubicacion1_.id
inner join
unidad_medida unidadmedi3_
on material0_1_.id_unidadmedida=unidadmedi3_.id

14:34:51,703 INFO [STDOUT] Hibernate:
select
categoriae0_.id as id4_0_,
categoriae0_.detalle as detalle4_0_,
categoriae0_.nombre as nombre4_0_,
categoriae0_.version as version4_0_
from
categoria_envase categoriae0_
where
categoriae0_.id=?

Problem:
To initialize the attribute "categoriaEnvase" of MaterialAcondicionamiento, Hibernate execute secondary selects. I want that execute a outer join. Is this possible?

Thanks.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.