-->
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: unidirectional one-to-many accociation on foreign key exampl
PostPosted: Thu Jun 30, 2005 12:01 pm 
Newbie

Joined: Tue Jun 28, 2005 11:11 am
Posts: 13
Location: St. Louis, Missouri, USA
Maybe it's just me, but I'm finding the xml mappings for Hibernate to be impossible. If someone could help out with this example, I'd be grateful.

I have two tables
AREA(area, area_id) -- They key is the whole row
DISTRICT (district_id, area_id, district) -- They key is the whole row

My pojo District object wants to know it's district_id, area_id, district, and the corresponding area to its area_id.

The sql would be something like:
Code:
Select district.district_id, district.district_name, district.district_area_id, area.area from AREA area, DISTRICT district  where area.AREA_ID = district.district_area_id and district_id = ?


I don't want to fuss with an Area object but would rather just query that AREA table for this one field. I believe this is a unidirectional one-to-many association on a foreign key. I'm not sure how to go about this with Hibernate since my "keys" are "composite" and I'm not doing a join.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 2:43 pm 
Newbie

Joined: Tue Jun 28, 2005 11:11 am
Posts: 13
Location: St. Louis, Missouri, USA
Is it possible to use a <formula> in an xml that will allow me to do what I want? I'd like that DistrictBO.area_id to reference the value area_id which is defined in this class but I don't know how to do that...
Code:
<hibernate-mapping>
<class name=".test.bo.DistrictBO" table="F_DISTRICT">
<id name="id" type="string" column="DISTRICT_ID" >
   <generator class="assigned"/>      
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="area_id"
   column="DISTRICT_AREA_ID"
/>
<property name="name"
column="DISTRICT_NAME"
/>
      
<property name="areaName" type="string">
<formula>
( select F_AREA.AREA from F_AREA WHERE F_AREA.AREA_ID = DistrictBO.area_id )
</formula>
</property>
      
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 18, 2005 11:11 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Leave out the DistrictBO bit:
Code:
<hibernate-mapping>
<class name=".test.bo.DistrictBO" table="F_DISTRICT">
   <id name="id" type="string" column="DISTRICT_ID" >
     <generator class="assigned"/>     
  </id>

  <property name="area_id" column="DISTRICT_AREA_ID"/>
  <property name="name" column="DISTRICT_NAME"/>
     
  <property name="areaName" type="string">
    <formula>
      ( select F_AREA.AREA from F_AREA WHERE F_AREA.AREA_ID = area_id )
    </formula>
  </property>
     
</class>
</hibernate-mapping>


Attributes with no table qualifier are assumed to refer to the table being loaded.


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.