-->
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: many to many mapping
PostPosted: Thu Mar 22, 2007 10:50 am 
Newbie

Joined: Thu Mar 22, 2007 10:39 am
Posts: 14
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


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.