-->
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: ManyToMany Spring Update
PostPosted: Mon Aug 08, 2011 2:47 am 
Newbie

Joined: Sat Jun 09, 2007 12:29 pm
Posts: 19
Hi,

We are using Spring for our development. In the project I have two entities - Iteration and Task which have ManyToMany relationship. Here is a definition:
Code:
@ManyToMany(
       targetEntity=Task.class,
       fetch = FetchType.LAZY,
       cascade = CascadeType.REMOVE
   )
   @JoinTable(
      name="Po_IterationTask",
       joinColumns=@JoinColumn(name="iterationUuid"),
       inverseJoinColumns=@JoinColumn(name="taskUuid")
   )
   private List<Task> tasks;

   public Iteration() {
      super();
   }



now when I add Tasks to an Iteration and save it, it works ok. The tasks are added to the Iteration. But then I'd like to save the Iteration. My controller method looks like this:

Code:
@RequestMapping(method={ RequestMethod.POST, RequestMethod.PUT })
   public @ResponseBody Map<String,? extends Object> save(@RequestBody Iteration iteration) {
      try{
         new ClassValidator<Iteration>(validator).validateRecord(iteration);
         crudService.save(iteration);
         return MessageProcessor.createRecordMessage(iteration);
      } catch (Exception e) {
         logger.error(e);
         return MessageProcessor.createError(e.getLocalizedMessage());
      }
   }


Of course as Iteration is submitted from the Spring form, there is no tasks in the Iteration object. When I store the Iteration - action produces deletion of existing task links added to the iteration.

How to resolve this, without manually updating the collections on all ManyToMany entities?

_________________
http://www.objectverse.com
http://www.alcyone.si
http://blog.alcyone.si


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.