-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping with join of two tables
PostPosted: Tue Aug 07, 2007 3:43 am 
Newbie

Joined: Tue Aug 07, 2007 3:19 am
Posts: 5
Trying to set up a joining of two tables. Using Hibernate 3.1.2 with the following signature:
Code:
<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


I have a Hibernate mapping against a database table which is working. However I have another table which contains extra information. I've tried a join in the mapping file but somehow it fails.

Lets call them Table1 og Table2.
Table1 has an attribute TAB1_Var_ID(not a primary key) and not defined as foreign key either(its an performance issue)
Table2 has a primary key TAB2_Var_ID which is connected to the TAB1_Var_ID
There is a many-to-one relationship.
Table1 can contain many TAB2_Var_ID

I am fairly new with Hibernate and don't have a clue what the cause of my problem is. Heres is my join mapping(with pseudonyms)

Code:
<hibernate-mapping>
<class name="SomeChildClass" table="Table1" lazy="false">
  <composite-id>
    <key-many-to-one..>
    <key-property..>
    <key-property..>
  </composite-id>
...
  <property name="varID" column="TAB1_Var_ID" type=integer" not-null="false"/>

  <join table="Table2>
    <key column="TAB1_Var_ID" property-ref="varID" unique="true"/>
    <property name="someText" column="TAB2_SOME_TEXT" type="string" not-null="false"/>
  </join>

</class>
</hibernate-mapping>


The variable someText and tab1VarID is in the SomeParentClass which SomeChildClass extends. SomeParentClass is not mapped.

The hibernate mapping is working without the join, but I need the someText value also in that mix.

I have tried reversing it with by mapping SomeParentClass and using <joined-subclass> with SomeChildClass, but I then get a syntax error on joined-subclass

Code:
<hibernate-mapping>
<class name="SomeParentClass" table="Table2" lazy="false">
    <id name="varID" column="TAB2_Var_ID" type="integer"/>
    <property name="someText" column="TAB2_SOME_TEXT" type="string" not-null="false"/>

  <joined-subclass>
    <composite-id>
      <key-many-to-one..>
      <key-property..>
      <key-property..>
    </composite-id>
    ...
    <property name="varID" column="TAB1_Var_ID" type=integer" not-null="false"/>
  </joined-subclass>

</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.