Hello,
I have 2 classes (Partner and PartnerDetails) connected by a one-to-one association; I run an HQL using LEFT JOIN FETCH in order to retrieve a Partner with its associated PartnerDetail using only one SELECT.
The strange behaviour is that the HQL returns an empty result while the generated SQL returns good data.
Here is the HQL:
Code:
FROM com.kertel.kercash.core.types.Partner AS partner
LEFT JOIN FETCH partner.details
WHERE partner.id =7
Strangely enough, the generated SQL returns 1 row. Here's the mappings of the two classes and Hiberantes trace logs.
I am using Hibernate 2.1.4 on a Sybase.
Thanks for any ideas!
Code:
<class
name="com.kertel.kercash.core.types.Partner"
table="partenaire"
>
<id name="id" column="part_id" type="long" unsaved-value="0">
<generator class="com.kertel.kercash.serialization.MaxIdGenerator" >
<param name="table-name">partenaire</param>
<param name="table-id">part_id</param>
<param name="counter-table-name">compteur</param>
</generator>
</id>
<property
name="name"
type="string"
column="part_nom" />
<set
name="sites"
table="site"
lazy="true"
inverse="true">
<key column="part_id" />
<one-to-many
class="com.kertel.kercash.core.types.Site" />
</set>
<one-to-one
name="details"
class="com.kertel.kercash.core.types.PartnerDetails"
outer-join="true"
cascade="none"
/>
</class>
Code:
<class
name="com.kertel.kercash.core.types.PartnerDetails"
table="partenaire_detail">
<id name="id" type="long" column="part_id" unsaved-value="0">
<generator class="foreign">
<param name="property">partner</param>
</generator>
<!--<generator class="assigned"></generator>-->
</id>
<one-to-one
name="partner"
class="com.kertel.kercash.core.types.Partner"
constrained="true"
outer-join="true" />
<property name="signatureDate" column="pard_datesignature" type="java.sql.Date"/>
<property name="siretNumber" column="pard_siret" type="string"/>
<property name="extranetLogin" column="pard_extranet_login" type="string"/>
<property name="extranetPassword" column="pard_extranet_password" type="string"/>
<property name="address1" column="pard_adresse1" type="string" />
<property name="address2" column="pard_adresse2" type="string"/>
<property name="address3" column="pard_adresse3" type="string"/>
<property name="city" column="pard_ville" type="string" />
<property name="state" column="pard_etat" type="string"/>
<property name="country" column="pard_pays" type="string" />
<property name="phone" column="pard_tel" type="string"/>
<property name="postCode" column="pard_codepostal" type="string"/>
<property name="fax" column="pard_fax" type="string"/>
<property name="invoiceAddress1" column="pard_adresse1_F" type="string"/>
<property name="invoiceAddress2" column="pard_adresse2_F" type="string"/>
<property name="invoiceAddress3" column="pard_adresse3_F" type="string"/>
<property name="invoiceCity" column="pard_ville_F" type="string"/>
<property name="invoiceCountry" column="pard_pays_F" type="string"/>
<property name="invoicePostCode" column="pard_codepostal_F" type="string"/>
<property name="invoiceState" column="pard_etat_F" type="string"/>
</class>
Hibernate's trace logs while executing the HQL query:
[code]
1047246 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - opened session
1047406 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - closing session
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - opened session
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - find: FROM com.kertel.kercash.core.types.Partner AS partner
LEFT JOIN FETCH partner.details
WHERE partner.id =7
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.engine.QueryParameters - named parameters: {}
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - Dont need to execute flush
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.hql.QueryTranslator - HQL: FROM com.kertel.kercash.core.types.Partner AS partner
LEFT JOIN FETCH partner.details
WHERE partner.id =7
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.hql.QueryTranslator - SQL: select partner0_.part_id as part_id0_, partnerdet1_.part_id as part_id1_, partner0_.part_nom as part_nom0_, partnerdet1_.pard_datesignature as pard_dat2_1_, partnerdet1_.pard_siret as pard_siret1_, partnerdet1_.pard_extranet_login as pard_ext4_1_, partnerdet1_.pard_extranet_password as pard_ext5_1_, partnerdet1_.pard_adresse1 as pard_adr6_1_, partnerdet1_.pard_adresse2 as pard_adr7_1_, partnerdet1_.pard_adresse3 as pard_adr8_1_, partnerdet1_.pard_ville as pard_ville1_, partnerdet1_.pard_etat as pard_etat1_, partnerdet1_.pard_pays as pard_pays1_, partnerdet1_.pard_tel as pard_tel1_, partnerdet1_.pard_codepostal as pard_co13_1_, partnerdet1_.pard_fax as pard_fax1_, partnerdet1_.pard_adresse1_F as pard_ad15_1_, partnerdet1_.pard_adresse2_F as pard_ad16_1_, partnerdet1_.pard_adresse3_F as pard_ad17_1_, partnerdet1_.pard_ville_F as pard_vi18_1_, partnerdet1_.pard_pays_F as pard_pa19_1_, partnerdet1_.pard_codepostal_F as pard_co20_1_, partnerdet1_.pard_etat_F as pard_et21_1_ from partenaire partner0_ left outer join partenaire_detail partnerdet1_ on partner0_.part_id=partnerdet1_.part_id where (partner0_.part_id=7 )
1051763 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
1051803 [AWT-EventQueue-0] DEBUG net.sf.hibernate.SQL - select partner0_.part_id as part_id0_, partnerdet1_.part_id as part_id1_, partner0_.part_nom as part_nom0_, partnerdet1_.pard_datesignature as pard_dat2_1_, partnerdet1_.pard_siret as pard_siret1_, partnerdet1_.pard_extranet_login as pard_ext4_1_, partnerdet1_.pard_extranet_password as pard_ext5_1_, partnerdet1_.pard_adresse1 as pard_adr6_1_, partnerdet1_.pard_adresse2 as pard_adr7_1_, partnerdet1_.pard_adresse3 as pard_adr8_1_, partnerdet1_.pard_ville as pard_ville1_, partnerdet1_.pard_etat as pard_etat1_, partnerdet1_.pard_pays as pard_pays1_, partnerdet1_.pard_tel as pard_tel1_, partnerdet1_.pard_codepostal as pard_co13_1_, partnerdet1_.pard_fax as pard_fax1_, partnerdet1_.pard_adresse1_F as pard_ad15_1_, partnerdet1_.pard_adresse2_F as pard_ad16_1_, partnerdet1_.pard_adresse3_F as pard_ad17_1_, partnerdet1_.pard_ville_F as pard_vi18_1_, partnerdet1_.pard_pays_F as pard_pa19_1_, partnerdet1_.pard_codepostal_F as pard_co20_1_, partnerdet1_.pard_etat_F as pard_et21_1_ from partenaire partner0_ left outer join partenaire_detail partnerdet1_ on partner0_.part_id=partnerdet1_.part_id where (partner0_.part_id=7 )
Hibernate: select partner0_.part_id as part_id0_, partnerdet1_.part_id as part_id1_, partner0_.part_nom as part_nom0_, partnerdet1_.pard_datesignature as pard_dat2_1_, partnerdet1_.pard_siret as pard_siret1_, partnerdet1_.pard_extranet_login as pard_ext4_1_, partnerdet1_.pard_extranet_password as pard_ext5_1_, partnerdet1_.pard_adresse1 as pard_adr6_1_, partnerdet1_.pard_adresse2 as pard_adr7_1_, partnerdet1_.pard_adresse3 as pard_adr8_1_, partnerdet1_.pard_ville as pard_ville1_, partnerdet1_.pard_etat as pard_etat1_, partnerdet1_.pard_pays as pard_pays1_, partnerdet1_.pard_tel as pard_tel1_, partnerdet1_.pard_codepostal as pard_co13_1_, partnerdet1_.pard_fax as pard_fax1_, partnerdet1_.pard_adresse1_F as pard_ad15_1_, partnerdet1_.pard_adresse2_F as pard_ad16_1_, partnerdet1_.pard_adresse3_F as pard_ad17_1_, partnerdet1_.pard_ville_F as pard_vi18_1_, partnerdet1_.pard_pays_F as pard_pa19_1_, partnerdet1_.pard_codepostal_F as pard_co20_1_, partnerdet1_.pard_etat_F as pard_et21_1_ from partenaire partner0_ left outer join partenaire_detail partnerdet1_ on partner0_.part_id=partnerdet1_.part_id where (partner0_.part_id=7 )
1051803 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
1051823 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - processing result set
1051823 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.LongType - returning '7' as column: part_id0_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.LongType - returning '7' as column: part_id1_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - result row: 7, 7
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - Initializing object from ResultSet: 7
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - Hydrating entity: com.kertel.kercash.core.types.Partner#7
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning 'ORT' as column: part_nom0_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - Initializing object from ResultSet: 7
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - Hydrating entity: com.kertel.kercash.core.types.PartnerDetails#7
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.DateType - returning '01 janvier 1900' as column: pard_dat2_1_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_siret1_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning 'ORT' as column: pard_ext4_1_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning 'brsn2635' as column: pard_ext5_1_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning '12, VILLA DE LOURCINE / 16-24, RUE CABANIS' as column: pard_adr6_1_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_adr7_1_
1052003 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_adr8_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning 'PARIS' as column: pard_ville1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_etat1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning 'FRANCE' as column: pard_pays1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_tel1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning '75014' as column: pard_co13_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_fax1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_ad15_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_ad16_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_ad17_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_vi18_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_pa19_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_co20_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.type.StringType - returning null as column: pard_et21_1_
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - done processing result set (1 rows)
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
1052023 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.loader.Loader - total objects hydrated: 2
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - resolving associations for [com.kertel.kercash.core.types.Partner#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - creating collection wrapper:[com.kertel.kercash.core.types.Partner.sites#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - loading [com.kertel.kercash.core.types.PartnerDetails#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - attempting to resolve [com.kertel.kercash.core.types.PartnerDetails#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - resolved object in session cache [com.kertel.kercash.core.types.PartnerDetails#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - done materializing entity [com.kertel.kercash.core.types.Partner#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - resolving associations for [com.kertel.kercash.core.types.PartnerDetails#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - loading [com.kertel.kercash.core.types.Partner#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - attempting to resolve [com.kertel.kercash.core.types.Partner#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - resolved object in session cache [com.kertel.kercash.core.types.Partner#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - done materializing entity [com.kertel.kercash.core.types.PartnerDetails#7]
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - initializing non-lazy collections
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.hql.QueryTranslator - compiling query
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - closing session
1052033 [AWT-EventQueue-0] DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
1052073 [AWT-EventQueue-0] WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Warning: 0, SQLState: 010SK
1052073 [AWT-EventQueue-0] WARN net.sf.hibernate.util.JDBCExceptionReporter - 010SK: La base de donn