-->
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.  [ 2 posts ] 
Author Message
 Post subject: Would like to <join> inside <component>
PostPosted: Wed Jun 13, 2007 4:32 pm 
Newbie

Joined: Mon May 08, 2006 8:48 am
Posts: 4
I have a relationship that would greatly benefit from being able to use the <join> clause inside of a component. It appears that this is not available... any reason why?

Just curious.

Think of this: (from section 7.3.2 of 3.2.3 reference manual)
Code:
<class name="Person">
  <id name="id" column="personId">
    <generator class="native"/>
  </id>
  <join table="PersonAddress" optional="true">
    <key column="personId" unique="true"/>
    <many-to-one name="address" column="addressId" not-null="true"/>
  </join>
</class>
<class name="Address">
  <id name="id" column="addressId">
    <generator class="native"/>
  </id>
</class>


like this:
Code:
<class name="Person">
  <id name="id" column="personId">
    <generator class="native"/>
  </id>
  <component name="contactInfo" class="ContactInfo">
    <join table="PersonAddress" optional="true">
      <key column="personId" unique="true"/>
      <many-to-one name="address" column="addressId" not-null="true"/>
    </join>
  </component>
</class>

<class name="Address">
  <id name="id" column="addressId">
    <generator class="native"/>
  </id>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 5:07 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
>>> It appears that this is not available... any reason why?
Usage of <many-to-one> ( set, list etc ) is allowed inside components.
So, it is possible to have associated entities.
<join table> is again a means ( and in many cases , the preferred one ) for defining (such) relationships.
Having said that, It looks perfectly valid to support them inside components.
This is my opinion. (Anybody) Please correct me if I am wrong.
I suggest raising a JIRA issue. ( after looking for existing requests, if any )

>>> would greatly benefit from being able to use the <join> clause inside of a component
Here's an alternative.
Check if it helps you.

i) Retain the join table mapping in the parent class.
ii) Use <parent> sub element in <component> to refer back to parent.


<component name="contactInfo" class="ContactInfo">
<parent name="parent" />
....


iii) Access associated entities through getters in component (child) class and delegate all operations to the parent's object.


class ContactInfo {
Person parent ; // with getters and setters
Address getAddress() { return parent.getAddress() ; }
}



Benefits:
At the application level, we access associated entities as if they are elements of component class.

-------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.