-->
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: Referenced Joined-Subclass with Relation-Key in Super Table
PostPosted: Tue Jun 06, 2006 1:34 pm 
Beginner
Beginner

Joined: Tue Mar 15, 2005 5:04 am
Posts: 26
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=?


Top
 Profile  
 
 Post subject: I think
PostPosted: Tue Jun 06, 2006 2:13 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Hello Friend:

After readed your post, i guess your can replace the line:

[code] <joined-subclass name="de.datentraum.allrounder.BaseClasses.KArticleRelation" table="k_article_relations">
[/code]

to

<subclass [u]discriminator-value="KKKK" [/u]name="e.datentraum.allrounder.BaseClasses.KArticleRelation">
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"/>
</subclass>


I guess that will solve your problem.

Ohh... the tag joined-subclass is used when you have "table inherited". So, when you have one table, and you want to specific their inherence, you can use "subclass" (Table "Person", may have two object with some operacion different: teacher, student, ando so on);

when you have more than one table that had [u]a some logic[/u], you can use joined-sublcass tag (example: the table Techer, Student, and so on)

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 2:42 pm 
Beginner
Beginner

Joined: Tue Mar 15, 2005 5:04 am
Posts: 26
Hi,

Thx for your reply.
The <subclass> Tag will not work, because I have the fields, that would come additionaly for the subclass in a second table.
So I did use the <joined-subclass>. And thats the situation i am in with the Problem described above.

greetings,
Alexander


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.