-->
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: bidirectional associations w/ <any>
PostPosted: Tue Sep 20, 2005 1:27 pm 
Newbie

Joined: Thu Sep 01, 2005 8:43 am
Posts: 14
Hi all,

I am struggling w/ the following problem: I have a bunch of classes that implement an interface (Extendable). All classes that extend the interface can be extended at runtime w/ additional attributes (0..n). Correspondingly the interface defines get/setAttributes and get/setAttribute(name).

An attribute is represented by an instance of the Attribute class.

The obvious solution is of course to manage a one-to-many association from any Extendable implementor to Attribute. Unfortunately currently I am expecting that the number of these implementors to be quite some, indeed all or almost all of the persistent classes. The idea of having a table w/ FKs to all other tables is somehow not quite...

Initially I found the idea of using <any> much better - this is also OK to map the relation between Attribute and Extendable. But I want also have a collection of all Attributes in the corresponding Extendable implementator, i.e. the other side of the association (and many-to-any is not the answer :) ).

Is there any possibility to achieve this, or should I initialize this collections manually w/ HQL?

Here the sources for the interface and the mapping of Attribute (the source of the latest is trivial)

Code:
public interface Extendable {
   public Map<String, Attribute> getBs();
   public void setBs(Map<String, Attribute> attributes);
   public void setB(String name, String value);
   public B getB(String name);
}


Code:
<hibernate-mapping package="entities">
   <class name="Attribute" table="attrubute">
      <id name="id">
         <generator class="native" />
      </id>

      <property name="name"></property>
      <property name="value"></property>

      <any name="extendable" id-type="long" meta-type="string" cascade="all">
                        <!-- Just some example entities -->
         <meta-value value="A" class="entities.A"/>
         <meta-value value="A2" class="entities.A2"/>
         <column name="ref_table"></column>
         <column name="ref_id"></column>
      </any>
   </class>
</hibernate-mapping>


BTW the relation can be unidirectional - so I do not need to know in a Attribute to which class it belongs.

Any help will be appriciated,
Thx in advance,
landels


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.