Hi,
i've the same problem using inheritance and native Queries. The resulting Query from Hibernate which is then send to DB is not correct.
F.e. We have a Customer (Kunde) - Table and an Person Table which has more than one inherited tables such as Natperson ... and so on.
The Query i wrote looks like:
"select {d.*},{k.*} from Kunde k inner join Person d on k.personid = d.personid"
and i added the two entities:
query.addEntity("d",Person.class);
query.addEntity("k",Kunde.class);
The Query which was than made from Hibernate looked like:
SELECT d.personid AS personid327_0_, d.anredeid AS anredeid327_0_,
d.old_instanzid AS old3_327_0_, d.mandantid AS mandantid327_0_,
d.persontypid AS personty5_327_0_, d_1_.mandantid AS mandantid328_0_,
d_1_.personid AS personid328_0_, d_1_.name1 AS name3_328_0_,
d_1_.NAME AS name328_0_, d_2_.spracheid AS spracheid329_0_,
d_2_.mandantid AS mandantid329_0_, d_2_.personid AS personid329_0_,
d_3_.personid AS personid330_0_, d_4_.subsystemid AS subsyste2_331_0_,
d_4_.subsyskey AS subsyskey331_0_, d_4_.mandantid AS mandantid331_0_,
d_4_.gueltig_bis AS gueltig5_331_0_, d_4_.personid AS personid331_0_,
d_4_.gueltig_ab AS gueltig6_331_0_,
d_5_.mediauntertypid AS mediaunt2_332_0_,
d_5_.subsystemid AS subsyste3_332_0_,
d_5_.subsyskey AS subsyskey332_0_, d_5_.nationid AS nationid332_0_,
d_5_.gueltig_bis AS gueltig6_332_0_, d_5_.personid AS personid332_0_,
d_5_.gueltig_ab AS gueltig7_332_0_, d_6_.mandantid AS mandantid333_0_,
d_6_.personid AS personid333_0_, d_7_.personid AS personid334_0_,
d_8_.spracheid AS spracheid335_0_, d_8_.mandantid AS mandantid335_0_,
d_8_.moechteanschnitt AS moechtea4_335_0_,
d_8_.personid AS personid335_0_, d_9_.spracheid AS spracheid336_0_,
d_9_.mandantid AS mandantid336_0_, d_9_.personid AS personid336_0_,
d_10_.gebdatum AS gebdatum337_0_,
d_10_.fremdschluessel AS fremdsch3_337_0_,
d_10_.mandantid AS mandantid337_0_, d_10_.personid AS personid337_0_,
d_10_.NAME AS name337_0_, d_10_.titelid AS titelid337_0_,
d_10_.vorname AS vorname337_0_, d_11_.sdatum AS sdatum338_0_,
d_11_.bemerkung AS bemerkung338_0_, d_11_.mandantid AS mandantid338_0_,
d_11_.personid AS personid338_0_,
CASE
WHEN d_6_.personid IS NOT NULL
THEN 6
WHEN d_7_.personid IS NOT NULL
THEN 7
WHEN d_2_.personid IS NOT NULL
THEN 2
WHEN d_3_.personid IS NOT NULL
THEN 3
WHEN d_4_.personid IS NOT NULL
THEN 4
WHEN d_5_.personid IS NOT NULL
THEN 5
WHEN d_8_.personid IS NOT NULL
THEN 8
WHEN d_9_.personid IS NOT NULL
THEN 9
WHEN d_11_.personid IS NOT NULL
THEN 11
WHEN d_1_.personid IS NOT NULL
THEN 1
WHEN d_10_.personid IS NOT NULL
THEN 10
WHEN d.personid IS NOT NULL
THEN 0
END AS clazz_0_,
k.kundeid AS kundeid461_1_, k.stammnummer AS stammnum2_461_1_,
k.fremdsyskey AS fremdsys3_461_1_, k.sdatum AS sdatum461_1_,
k.bezeichnung AS bezeichn5_461_1_, k.spracheid AS spracheid461_1_,
k.edatum AS edatum461_1_, k.ustdident AS ustdident461_1_,
k.mandantid AS mandantid461_1_, k.personid AS personid461_1_,
k.kundetypid AS kundetypid461_1_, k.fremdsystemid AS fremdsy12_461_1_
FROM kunde k INNER JOIN person d ON k.personid = d.personid
So as you can see, Hibernate recognizes all inherited tables/objects from Person (in query named as d_1_...d_10_..) but Hibernate did not extend the from clause as needed. So the Query must fail with unknown aliases (d_1...d_10_) for tables.
Why does Hibernate also try to fetch and query inherited tables while using native queries as it's also using HQL.
Is there a way to disable this? In case inherited tables/objects have not to be fetched which would also be faster.
Thanks,
Heiko
|