Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除spring MVC中的操作_Java_Spring_Hibernate_Spring Mvc - Fatal编程技术网

Java 删除spring MVC中的操作

Java 删除spring MVC中的操作,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,用户和检查点具有多对多关系。我可以在数据库中保存值,但不能从数据库中删除值 User.java @Id @GeneratedValue private Integer id; @ManyToMany Set<Roles> roles; @ManyToMany(fetch = FetchType.EAGER) List<Checkpoints> checkpoints; public User() { super(); } public Integer ge

用户和检查点具有多对多关系。我可以在数据库中保存值,但不能从数据库中删除值

User.java

@Id
@GeneratedValue
private Integer id;
@ManyToMany
Set<Roles> roles;

@ManyToMany(fetch = FetchType.EAGER) 
List<Checkpoints> checkpoints;

public User() {
    super();
}

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public List<Checkpoints> getCheckpoints() {
    return checkpoints;
}

public void setCheckpoints(List<Checkpoints> checkpoints) {
    this.checkpoints = checkpoints;
}
在我的UserDaoImpl中

@Transactional 
@Override
public User saveUser(User user) {
    // TODO Auto-generated method stub 
    return entityManager.merge(user);
}
请让我知道我做错了什么,或者用其他方法做同样的事情!!
提前谢谢

你的许多注释上的级联属性?@NeilMcGuigan感谢你的研究!!我刚找到解决办法!!我正在从user(存储在会话中)而不是userDao中删除检查点对象。
@RequestMapping(value="/checkpointadd.html", method = RequestMethod.POST) 
public void checkpoint(@RequestParam Integer categoryId, HttpSession    session){    // This works fine
    System.out.println("Checkpoint checked :"+categoryId); 
    User user = (User) session.getAttribute("loggeduser");
    Checkpoints cp = userDao.getCheckpointById(categoryId);
    user.getCheckpoints().add(cp);
    userDao.saveUser(user);
    user.getCheckpoints().remove(cp);
}

@RequestMapping(value="/checkpointremove.html", method = RequestMethod.POST) 
public void checkpointremove(@RequestParam Integer categoryId, HttpSession session){   // I'm doing something wrong here
    System.out.println("Checkpoint removed :"+categoryId); 
    User user = (User) session.getAttribute("loggeduser");
    Checkpoints cp = userDao.getCheckpointById(categoryId);
    user.getCheckpoints().remove(cp);
    userDao.saveUser(user);
}
@Transactional 
@Override
public User saveUser(User user) {
    // TODO Auto-generated method stub 
    return entityManager.merge(user);
}