Hi,
I am having a problem with getting Referenced Object from the Database.
article_relation is a table, that contains a foreign key for articles.
k_article_relation is a second table, that contains all columns for the
Code:
class KArticleRelation extends ArticleRelation
The Article Mapping contains a map for KArticleRelation with the key article_id.
The problem now is, that hibernate tries to select the article_id field in the subclass-Table k_article_relation. But this field is only situated in the super-Table article_relation
ERROR:java.sql.SQLException: ERROR: column krelations0_.article_id does not exist
Hehe, this is true. But I want hibernate to access krelations0_1_.article_id anyway because thats the place where it exists.
Is there any way to change hibernates behavior?
Hibernate version:3.1.3 Mapping documents: Code:
<class name="de.datentraum.allrounder.BaseClasses.ArticleRelation" table="article_relations" discriminator-value="AR" lazy="false" abstract="true">
<id name="id" type="int" column="relation_id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">uid_article_relation</param>
</generator>
</id>
<!-- <discriminator column="disc"/> -->
<property name="price" column="price" type="double"/>
<property name="partnerNumber" column="partner_article_number"/>
<property name="partnerDescription" column="partner_article_description"/>
<many-to-one name="article" column="article_id" class="de.datentraum.allrounder.BaseClasses.Article"/>
<many-to-one name="account" column="account_id" class="de.datentraum.allrounder.BaseClasses.Account"/>
<joined-subclass name="de.datentraum.allrounder.BaseClasses.KArticleRelation" table="k_article_relations">
<key column="relation_id"/>
<property name="discount" column="discount" type="int"/>
<property name="minAmount" column="min_amount" type="int"/>
<property name="deliveryCosts" column="delivery_costs" type="double"/>
<property name="deliveryTime" column="delivery_time" type="int"/>
<property name="packageCosts" column="package_costs" type="double"/>
<property name="packageAmount" column="package_amount" type="int"/>
</joined-subclass>
<joined-subclass name="de.datentraum.allrounder.BaseClasses.DArticleRelation" table="d_article_relations">
<key column="relation_id"/>
</joined-subclass>
</class>
Code:
<class name="de.datentraum.allrounder.BaseClasses.Article" table="article" discriminator-value="A" lazy="false">
<id name="id" type="int" column="article_id" unsaved-value="0">
<generator class="sequence">
<param name="sequence">uid_article</param>
</generator>
</id>
<discriminator column="disc"/>
<property name="Articlenumber" not-null="true"/>
<property name="Description1"/>
<property name="Description2"/>
<property name="Sign" type="int"/>
<many-to-one name="chapter" column="chapter" class="de.datentraum.allrounder.BaseClasses.Chapter" lazy="false"/>
<many-to-one name="unit" column="unit" class="de.datentraum.allrounder.BaseClasses.Unit" lazy="false"/>
<property name="Vol" column="volume" type="double"/>
<property name="Weight" column="weight" type="double"/>
<property name="Specs"/>
<property name="Brand"/>
<map name="taxConditions" table="article_taxcond">
<key column="article_id"/>
<map-key column="taxcond_id" type="int"/>
<many-to-many column="tax" class="de.datentraum.allrounder.BaseClasses.Tax"/>
</map>
<set name="Krelations">
<key column="article_id"/>
<one-to-many class="de.datentraum.allrounder.BaseClasses.KArticleRelation"/>
</set>
<!-- <set name="Drelations">
<key column="article_id"/>
<one-to-many class="de.datentraum.allrounder.BaseClasses.DArticleRelation"/>
</set>-->
</class>
The generated SQL (show_sql=true):
select
krelations0_.article_id as article8_4_,
krelations0_.relation_id as relation1_4_,
krelations0_.relation_id as relation1_2_3_,
krelations0_1_.price as price2_3_,
krelations0_1_.partner_article_number as partner3_2_3_,
krelations0_1_.partner_article_description as partner4_2_3_,
krelations0_1_.article_id as article5_2_3_,
krelations0_1_.account_id as account6_2_3_,
krelations0_.discount as discount3_3_,
krelations0_.min_amount as min3_3_3_,
krelations0_.delivery_costs as delivery4_3_3_,
krelations0_.delivery_time as delivery5_3_3_,
krelations0_.package_costs as package6_3_3_,
krelations0_.package_amount as package7_3_3_,
article1_.article_id as article1_0_0_,
article1_.Articlenumber as Articlen3_0_0_,
article1_.Description1 as Descript4_0_0_,
article1_.Description2 as Descript5_0_0_,
article1_.Sign as Sign0_0_,
article1_.chapter as chapter0_0_,
article1_.unit as unit0_0_,
article1_.volume as volume0_0_,
article1_.weight as weight0_0_,
article1_.Specs as Specs0_0_,
article1_.Brand as Brand0_0_,
chapter2_.chapter_id as chapter1_16_1_,
chapter2_.chapter as chapter16_1_,
chapter2_.description as descript3_16_1_,
unit3_.unit_id as unit1_15_2_,
unit3_.name as name15_2_
from k_article_relations krelations0_
inner join article_relations krelations0_1_ on krelations0_.relation_id=krelations0_1_.relation_id
left outer join article article1_ on krelations0_1_.article_id=article1_.article_id
left outer join chapter chapter2_ on article1_.chapter=chapter2_.chapter_id
left outer join unit unit3_ on article1_.unit=unit3_.unit_id
where krelations0_.article_id=?