从来就得到了这个父对象JPA,合并对象更新儿童
@OneToMany(mappedBy="idUser", cascade = CascadeType.MERGE)
public List<Directions> directions;
从来就上,并在我的控制器得到这个
public static void userUpdate(String apikey, JsonObject body) {
if(validate(apikey)) {
Long idUser = decode(apikey);
User oldUser = User.findById(idUser);
Map<String, User> userMap = new HashMap<String, User>();
Type arrayListType = new TypeToken<Map<String, User>>(){}.getType();
userMap = gson().fromJson(body, arrayListType);
User user = userMap.get("user");
oldUser.em().merge(user);
oldUser.save();
}else{
forbidden();
}
}
这使得父对象上的更新,但当我更改子对象上的某些东西时,它不会更新它,也不会给hibernate或Oracle带来问题。
有谁知道为什么它不会更新子对象?
谢谢大家!
更新了解决方案!
这就是它对我的作用,因为@JB Nizet说你也必须保存子对象。
oldUser.em().merge(user);
oldUser.save();
for (Direction direction : oldUser.directions) {
direction.save();
}
另一种说法!
由于能够使oldUser.save(),并得到挽救了孩子的对象这
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "SASHNBR", insertable = true, updatable = true)
public List<Direction> directions;
从来就。
难道你看http://stackoverflow.com/questions/2530498/jpa-persisting-object-parent-is-ok-但孩子没有更新 – rayyildiz
@rayyildiz我做了,如果你看看我实现CascadeType.MERGE这是我想要的代码。无论如何,我会尝试与CascadeType.ALL。谢谢! :) – axierjhtjz
@rayyildiz也没有工作。 :( – axierjhtjz