日期:2014-05-20 浏览次数:20904 次
org.springframework.dao.InvalidDataAccessApiUsageException:[color=#FF6600] detached entity passed to persist[/color]: com.myproject.hrsystem.entity.Post; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.myproject.hrsystem.entity.Post
Department类: @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "TBL_DeptPost", joinColumns = { @JoinColumn(name = "dept_ID") }, inverseJoinColumns = { @JoinColumn(name = "post_Id") }) public Set<Post> getPosts() { return posts; } Post类: @ManyToMany(mappedBy = "posts",cascade = CascadeType.ALL) public Set<Department> getDepartments() { return departments; }
Set<Post> posts = new HashSet<Post>(); Company cmp = new Company();// 设置公司信息 cmp.setCmpId(1); String[] postIds = request.getParameterValues("select2");// 获取部门ID // 如果职位ID数组不为空,则循环遍历职位数组,取出职位ID if (StringUtil.isNullOrEmpty(postIds)) { for (String s : postIds) { Integer pid = Integer.parseInt(s); // 获取职位ID Post tempPost = new Post(); System.out.println("职位ID:-----"+pid); tempPost.setPostId(pid); posts.add(tempPost); // 将职位信息添加到集合中 } } dept.setPosts(posts);// 所属职位 dept.setCmp(cmp);// 所属公司 dept.setEmpId(empId);// 部门经理 dept.setAddId(empId);// 建立人 dept.setAddTime(new Date());// 建立时间 dept.setDelSt(0);// 删除标识