hey!
I'm kinda new to Hibernate, but I want to map some specific stuff:
I have a many to many relationship, which relation table has some extra attributes. Because of that, I need an extra mapping file for the relationship table.
Now, as I want to keep a Map<String, Relation> at one of the 2 sides, I'm trying to map this so that it fetches all relations automatically when fetching this object. The 'String' is then a value of the other side of the relationship.
I tried for quite some time now to get things to work, but as I'm new to this, I probably forgot some obvious things.
Implementing this with a Set was quite easy, but now..
mapping of sideA: Task:
Code:
<class name="domain.Task" table="Task">
<id name="id"
column="Task_Id"
unsaved-value="-1">
<generator class="native" />
</id>
<set name="input" cascade="all" inverse="true" lazy="true">
<key column="Task_Id"/>
<one-to-many class="domain.VariableAssignedIn"/>
</set>
...
</class>
mapping of sideB: Variable:
Code:
<class name="domain.VariableIn" table="VariableIn">
<id name="id"
column="Variable_Id"
unsaved-value="-1">
<generator class="native" />
</id>
<!-- the String needed in the relationship-map -->
<property name="label"
column="Variable_Label"
type="string"
length="30"
not-null="true"
unique="true"
/>
...
</class>
mapping of relationship:
Code:
<class name="domain.VariableAssignedIn" table="Task_VariableIn">
<composite-id>
<key-many-to-one
name="task"
class="domain.Task"
column="Task_Id"
/>
<key-many-to-one
name="variable"
class="domain.VariableIn"
column="Variable_Id"
/>
</composite-id>
<property name="value"
column="Value"
type="string"
length="100"
/>
</class>
any suggestions?
thanks in advance,
Sven