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