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: I can't remove association between two tables, many-to-many
PostPosted: Thu Feb 08, 2007 9:34 am 
Newbie

Joined: Thu Jan 25, 2007 7:58 am
Posts: 1
Need help with Hibernate's mapping.
I have two tables, many-to-many.
tbUsers and tbTasks
I can't remove association in table of associations tbUserTask2, but i can add association. Why? Help me, please.
table tbUsers
UID (PK)
....

table tbTasks
TID (PK)
.......

table tbUserTask2
UID
TID

user.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-lazy="false">
    <class name="webmin.model.User" table="tbUsers" schema="dbo" catalog="WebminDB">
        <id name="uid" type="java.lang.Long">
            <column name="UID" precision="18" scale="0" />
            <generator class="increment" />
        </id>
        </many-to-one>
        <set name="tasks" table="tbTaskUser2" cascade="delete-orphan">
            <key column="UID" />           
            <many-to-many column="TID" class="webmin.model.Task" />
        </set>         
        ..........     
    </class>
</hibernate-mapping>



task.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="true" default-lazy="false">
    <class name="webmin.model.Task" table="tbTasks" schema="dbo" catalog="WebminDB">
        <id name="tid" type="java.lang.Long">
            <column name="TID" precision="18" scale="0" />
            <generator class="increment" />
        </id>
        <set name="users" table="tbTaskUser2" inverse="true" cascade="delete-orphan">
            <key column="TID"/>
            <many-to-many column="UID" class="webmin.model.User" />
        </set>       
        ........
    </class>
</hibernate-mapping>


Part of code, i try to remove (it is controller in spring application)
Code:
protected void doSubmitAction(Object command) throws Exception {
      UserTaskCommand UTCommand = (UserTaskCommand)command;      
      User user = userService.getUser(UTCommand.getUid());
      Task task = taskService.getTask(UTCommand.getTid());
      user.getTasks().remove(task);
      task.getUsers().remove(user);
      userService.updateUser(user);
      taskService.updateTask(task);
   }
   

add
Code:
public void updateUser(User user) {
       getHibernateTemplate().update(user);
}


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.