All,
We have just migrate from Hibernate 3.2.5 (GA) to Hibernate 3.6.7 (Final).
After updating dialect (we were using Sybase 12.5 with SybaseDialect and migrated to Sybase ASE 15 with SybaseASE15Dialect) and 2-3 Maven dependances (
slf4j-log12,...) everything (
almost...) seems to be working.
But, we discovered, with an initially huge query, that this version of Hibernate duplicates some joins (inner joins in our case), which may lead to overtake Sybase (specifications...) limits of 50 tables/views access with a single query.
Without taking care of the initial query which could certainly be improved, as a general result, all queries have more joins meaning all queries take more time. Which is not exactly what we expected when we started the migration!
Below is a sample case to illustrate this.
(I'm french so fields in my DB are in french... but to help you understanding the sample, an Agriculteur is a Farmer, the EtatAgriculteur is the State of the farmer (from a professional point of view -does he grow cows, does he cultivate cereals, etc...) and the Parcelle are Field (to cultivate cereals, to grow cows...)Relationnal point-of-view : An
Agriculteur may have several
EtatAgriculteur (many-to-one relation) while this
Agriculteur may have 'n'
Parcelle. A
Parcelle may be owned only by one
Agriculteur. For the Agriculteur, this is a one-to-many relation.
The query below, is trying to retrieve all
Parcelle, associating with them the
Agriculteur and their
EtatAgriculteur.
I used P6Spy to catch the SQL produced by Hibernate after translating the HQL query.
Initial HQL query:Code:
from Parcelle p inner join p.agriculteur as agri inner join p.agriculteur.etatAgriculteur as etat where (p.agriculteur.agrCdn = agri.agrCdn and agri.etatAgriculteur.etatCdn = etat.etatCdn)
SQL translation done by Hibernate 3.2.5.GACode:
select parcelle0_.PAR_CDN as PAR1_36_0_, agriculteu1_.AGR_CDN as AGR1_27_1_, etatagricu3_.ETAT_CDN as ETAT1_33_2_, parcelle0_.PAR_LIB_LB as PAR2_36_0_, parcelle0_.PAR_SURFACE_INT as PAR3_36_0_, parcelle0_.PAR_CADAST_LB as PAR4_36_0_, parcelle0_.AGR_CDN as AGR5_36_0_, agriculteu1_.AGR_NOM_LB as AGR2_27_1_, agriculteu1_.AGR_PRENOM_LB as AGR3_27_1_, agriculteu1_.AGR_ADR1_LB as AGR4_27_1_, agriculteu1_.AGR_ADR2_LB as AGR5_27_1_, agriculteu1_.AGR_ACTIF_ON as AGR6_27_1_, agriculteu1_.AGR_CODPOS_LB as AGR7_27_1_, agriculteu1_.TYPE_CDN as TYPE8_27_1_, agriculteu1_.ETAT_CDN as ETAT9_27_1_, agriculteu1_.AGR_PERE_CDN as AGR10_27_1_, agriculteu1_.COM_CP_RFA as COM11_27_1_, agriculteu1_.COM_INSEE_RFA as COM12_27_1_, agriculteu1_.JUR_CDN as JUR13_27_1_, etatagricu3_.ETAT_LIB_LB as ETAT2_33_2_, etatagricu3_.ETA_RFA as ETA3_33_2_
from PARCELLE parcelle0_
inner join AGRICULTEUR agriculteu1_ on parcelle0_.AGR_CDN=agriculteu1_.AGR_CDN
inner join ETAT_AGRICULTEUR etatagricu3_ on agriculteu1_.ETAT_CDN=etatagricu3_.ETAT_CDN
where parcelle0_.AGR_CDN=agriculteu1_.AGR_CDN and agriculteu1_.ETAT_CDN=etatagricu3_.ETAT_CDN
SQL translation done by Hibernate 3.6.7.Final :Code:
select parcelle0_.PAR_CDN as PAR1_36_0_, agriculteu1_.AGR_CDN as AGR1_27_1_, etatagricu3_.ETAT_CDN as ETAT1_33_2_, parcelle0_.PAR_LIB_LB as PAR2_36_0_, parcelle0_.PAR_SURFACE_INT as PAR3_36_0_, parcelle0_.PAR_CADAST_LB as PAR4_36_0_, parcelle0_.AGR_CDN as AGR5_36_0_, agriculteu1_.AGR_NOM_LB as AGR2_27_1_, agriculteu1_.AGR_PRENOM_LB as AGR3_27_1_, agriculteu1_.AGR_ADR1_LB as AGR4_27_1_, agriculteu1_.AGR_ADR2_LB as AGR5_27_1_, agriculteu1_.AGR_ACTIF_ON as AGR6_27_1_, agriculteu1_.AGR_CODPOS_LB as AGR7_27_1_, agriculteu1_.TYPE_CDN as TYPE8_27_1_, agriculteu1_.ETAT_CDN as ETAT9_27_1_, agriculteu1_.AGR_PERE_CDN as AGR10_27_1_, agriculteu1_.COM_CP_RFA as COM11_27_1_, agriculteu1_.COM_INSEE_RFA as COM12_27_1_, agriculteu1_.JUR_CDN as JUR13_27_1_, etatagricu3_.ETAT_LIB_LB as ETAT2_33_2_, etatagricu3_.ETA_RFA as ETA3_33_2_
from PARCELLE parcelle0_
inner join AGRICULTEUR agriculteu1_ on parcelle0_.AGR_CDN=agriculteu1_.AGR_CDN
[b][u]inner join AGRICULTEUR agriculteu2_ on parcelle0_.AGR_CDN=agriculteu2_.AGR_CDN [/u][/b]
inner join ETAT_AGRICULTEUR etatagricu3_ on agriculteu2_.ETAT_CDN=etatagricu3_.ETAT_CDN
where parcelle0_.AGR_CDN=agriculteu1_.AGR_CDN and agriculteu1_.ETAT_CDN=etatagricu3_.ETAT_CDN
The second inner join (where I tried to put the U & B BBCode tags is the one added by Hbn3.6.7.Is there anyone who could help me trying to understand why Hb,3.6.7 duplicates the joins and how we could solve this?
Thanks,
Olivier.