-->
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.  [ 3 posts ] 
Author Message
 Post subject: null foreign key and outer join
PostPosted: Wed Sep 29, 2004 8:33 am 
Newbie

Joined: Fri Mar 05, 2004 11:20 am
Posts: 5
Hibernate version:
Hibernate 2.1.4

Mapping documents:
Note I removed properties not needed for my question!

<hibernate-mapping>
<class name="vo.T780Attivita" table="T780_ATTIVITA">
<id name="id" column="ID_ATTIVITA">
<generator class="sequence">
<param name="sequence">S780_ATTIVITA</param>
</generator>
</id>

<many-to-one
name="struttura"
column="FK_STRUTTURA_DEFAULT"
class="it.regioneveneto.decreti.vo.T300StruttureRegionali"
cascade="none"
outer-join="true"
not-null="false" />
</class>
</hibernate-mapping>

<hibernate-mapping>
<class lazy="true" name="vo.T300StruttureRegionali" table="T300_STRUTTURE_REGIONALI">

<id name="id" column="C_ID_STRUTTURA" type="string">
<generator class="assigned">
</generator>
</id>

<many-to-one
name="tipoStrutture"
column="C_FK_TIPO_STRUTTURA"
class="it.regioneveneto.decreti.vo.T300TipoStrutture"
cascade="none" />
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="vo.T300TipoStrutture" table="T300_TIPO_STRUTTURE">
<id name="id" column="C_ID_TIPO_STRUTTURA" type="string">
<generator class="assigned">
</generator>
</id>

</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
simplyfing.... I create a criteria starting from vo.T780Attivita and adding a like expression with value "%" on a property as shown by sql generated

Full stack trace of any exception that occurs:
No exception

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

The generated SQL (show_sql=true):

select this.ID_ATTIVITA as ID_ATTIV1_2_, this.COD_ATTIVITA as COD_ATTI2_2_, this.CREATED_BY as CREATED_BY2_, this.DE_ATTIVITA as DE_ATTIV4_2_, this.FLG_MODIFICA_DATI as FLG_MODI5_2_, this.FLG_STR_DEF_MODIFICABILE as FLG_STR_6_2_, this.MODIFIED_BY as MODIFIED7_2_, this.TIMEST_CREATED as TIMEST_C8_2_, this.TIMEST_MODIFIED as TIMEST_M9_2_, this.FK_STRUTTURA_DEFAULT as FK_STRU10_2_, x0_.C_ID_STRUTTURA as C_ID_STR1_0_, x0_.C_COD_SEGRETERIA as C_COD_SE2_0_, x0_.C_COD_AREA as C_COD_AREA0_, x0_.C_COD_DIREZIONE as C_COD_DI4_0_, x0_.C_COD_SERVIZIO as C_COD_SE5_0_, x0_.C_COD_UFFICIO as C_COD_UF6_0_, x0_.C_DS_STRUTTURA as C_DS_STR7_0_, x0_.C_DE_STRUTTURA as C_DE_STR8_0_, x0_.C_VL_INIZIO as C_VL_INI9_0_, x0_.C_VL_FINE as C_VL_FINE0_, x0_.C_FK_TIPO_STRUTTURA as C_FK_TI11_0_, t300tipost2_.C_ID_TIPO_STRUTTURA as C_ID_TIP1_1_, t300tipost2_.C_COD_TIPO_STRUTTURA as C_COD_TI2_1_, t300tipost2_.C_DS_TIPO_STRUTTURA as C_DS_TIP3_1_, t300tipost2_.C_DE_TIPO_STRUTTURA as C_DE_TIP4_1_, t300tipost2_.C_VL_INIZIO as C_VL_INI5_1_, t300tipost2_.C_VL_FINE as C_VL_FINE1_ from T780_ATTIVITA this, T300_STRUTTURE_REGIONALI x0_, T300_TIPO_STRUTTURE t300tipost2_ where lower(this.DE_ATTIVITA) like ? and this.FK_STRUTTURA_DEFAULT=x0_.C_ID_STRUTTURA and x0_.C_FK_TIPO_STRUTTURA=t300tipost2_.C_ID_TIPO_STRUTTURA(+)


Debug level Hibernate log excerpt:


Hi all,
when I search by Criteria for object of type vo.T780Attivita not all the outer join are performed.
This is a problem because there are null-able foreign key then the query return no row. I note a strange behavior, the relation (vo.T300StruttureRegionali)->(vo.T300TipoStrutture) is rapresented in sql with an outer join, instead the relation (vo.T780Attivita)->(vo.T300StruttureRegionali) is rapresented with a normal join (fk=id), also if I add outer-join="true" and not-null="false" on the many-to-one relation on vo.T780Attivita (I also added the lazy="true" on class "vo.T300StruttureRegionali" to force no join in this search, but does not work):
<many-to-one
name="struttura"
column="FK_STRUTTURA_DEFAULT"
class="it.regioneveneto.decreti.vo.T300StruttureRegionali"
cascade="none"
outer-join="true"
not-null="false" />

Somebody has an idea of what i'm doing wrong? I have no explanation.

enqnck


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 12:06 pm 
Newbie

Joined: Fri May 11, 2007 11:17 am
Posts: 2
Location: buenos aires
Somebody knows what this happening?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 8:11 am 
Newbie

Joined: Fri May 11, 2007 11:17 am
Posts: 2
Location: buenos aires
Somebody knows what this happening?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.