-->
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 relation with extra column
PostPosted: Tue Jun 01, 2010 3:52 am 
Newbie

Joined: Tue Jun 01, 2010 3:41 am
Posts: 1
Dear experts,

I am facing problem in composite-element mapping of hibernate. My expected relation is many to many in document and task. That is a task may have multiple documents and a document may have assigned to multiple task. Relational table will contain both foreign keys with additional column.

My Task hbm file:
Code:
 
<class name="com.dmcs.model.tm.TaskInfo" table="TM_TASK">
         <id name="taskId" column="TASK_ID">
             <generator class="increment" />
       </id>
      <property name="taskUdId" column="TASK_UDID" />       
       
       <set  name="docInfoList"  table="TM_TASKDOCS"  cascade="save-update">
         <key column="taskId" />    
                  
      <composite-element class="com.dmcs.model.tm.TaskDocsInfo">      
         <many-to-one name="docInfo" column="documentId" class="com.dmcs.model.document.DocumentInfo" />
         <property name="rmks" column="RMKS"/>
      </composite-element>
      
      </set>
      
       </class>

 


My document hbm file:
Code:
   
<class name="com.dmcs.model.document.DocumentInfo" table="DOCUMENT">
      
      <id name="documentId" column="DOC_ID">
         <generator class="increment" />
      </id>      
      <property   name="fileName" column="FILENAME" />               
      
      <set  name="taskInfoList"  table="TM_TASKDOCS" cascade="save-update">
         <key column="documentId" />
         <many-to-many  column="taskId" class="com.dmcs.model.tm.TaskInfo" />      
      </set>
         
   </class>


Suppose I want to create a new task T1 (not already save in database) with assigned three Documents(D1,D2,D3 ;assume D1, D2, D3 already saved in database). what will be the TaskDocsInfo class code exactly? I have tried with the following code but fails

Code:
   
                taskInfo = new TaskInfo();
      taskInfo.getDocInfoList().add(D1);
      taskInfo.getDocInfoList().add(D2);
      taskInfo.getDocInfoList().add(D3);      
      
      taskInfo.setTaskUdId(taskUdId);      
      
              //insert into data base
      Session session = HibernateUtil.getSession();
      Transaction tx = null;
   
      try
      {
         tx = session.beginTransaction();
         session.merge(taskInfo);
         tx.commit();
      }
      catch (Exception e)
      {
         if(tx != null) tx.rollback();
         e.printStackTrace();
         
      }
      finally
      {
         session.close();
      }



Please help.

Thanks in advance


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.