in one particular case, i have to use merge instead of saveOrUpdate.
//
// item is detached object.
//
Category category = item.getCategory();
category.setName("cloth");
item.setName("shirt");
session.merge(item);
the thing is category name doesn’t get updated while using merge, but it gets updated while using saveOrUpdate. anyone can explain why?
You must have
@ManyToOne(cascade=CascadeType.MERGE)(at least) for that to work (or the relevant xml mapping)This instructs hibernate to cascade merge operations to this particular relation – i.e. when the parent object (item) is merged, also merge the child (category). Maybe you have omitted the
MERGEcascade type, and that’s whysaveOrUpdateworks.