I have two different pages where different parts of an object can be added/updated. One main screen where simple information like name etc are specified and another form where a child collection is updated. If I have 2 elements added to the child collection and then go back into the general form and resave the data, it wipes out the child collections here is the code
Code:/*** StoreContoller.java ***/ @RequestMapping(value = "/store", method = RequestMethod.GET) public String store(@RequestParam(defaultValue="") String storeId, Model model){ //updating existing store if(!storeId.equals("")){ model.addAttribute("store", storeDao.getStoreById(storeId)); } //adding new store else{ model.addAttribute("store", new Store()); } return "store"; } @RequestMapping(value = "/store", method = RequestMethod.POST) public String storeSubmit(@Valid Store store, BindingResult result){ if(!result.hasErrors()){ //now save the store log.debug("adding/updating store " + store); storeDao.saveStore(store); return "redirect:/"; } log.error("error in binding store", result.toString()); return "store"; }Code:/*** StoreDoa */ public void saveStore(Store store){ log.debug("saving store " + store); Session session = sessionFactory.getCurrentSession(); session.saveOrUpdate(store); session.flush(); }Code:/**** Store.java */ @Entity @Table(name="clicksvn_stores") public class Store implements Serializable { @Id private String id = IDGenerator.createId(); @NotEmpty private String name; @NotEmpty private String server; @NotEmpty private String username; @NotEmpty private String password; private String schedulingExpression; private boolean scheduled; @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, orphanRemoval=true) @JoinColumn(name="store_id") private Collection<Project> projects = new LinkedHashSet<Project>(); ..... }Any help would be appreciated. I have tried specifying dynamic update as true on Store entity but still doesnt helps.Code:/**** Project class */ @Entity @Table(name="clicksvn_store_projects") public class Project implements Serializable { private static final long serialVersionUID = -276787615885478824L; @Id private String id = IDGenerator.createId(); private String internalName; private String displayName; @ManyToOne @JoinColumn(name="store_id", insertable=false, updatable=false) private Store store; ... }


Reply With Quote
