我有两个实体。一个实体条件具有与站点的OneToMany映射,而其他实体站点具有manyToOneMapping with Conditions。现在我想复制具有所有属性的条件更新几个值并将其作为新实体保留。
public class Condition{
@OneToMany(cascade = CascadeType.ALL,mappedBy = "condition",fetch=FetchType.EAGER)
private List<Sites> sites;
}
public class Sites{
@ManyToOne(targetEntity=Condition.class,fetch=FetchType.LAZY)
@JoinColumn(name = "conditionId")
private condition condition;
}
在服务层我完成了这个: -
entityManager.detach(condition);
condition.setId(0L);
conditionRepository.save(condition);
我收到以下错误: -
{
"timestamp": 1509530470031,
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.RuntimeException",
"message": "javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: co.src..entity.condition",
"path": "/project/reviseProjectDetails"
}
任何了解此问题的人都请帮忙!!
答案 0 :(得分:0)
select a.Company_name as Company_name,First_name as first_name, Last_name as last_name,nc from
(select Company_name,
contact_id,
count(Issue.Caller_id) as nc
from Issue
join Caller on Caller.Caller_id = Issue.Caller_id
join Customer on Caller.Company_ref = Customer.Company_ref
group by Company_name,Contact_id
having count(Issue.Caller_id) < 5
order by nc desc) a
join
(select * from Caller) b
on a.contact_id = b.Caller_id
表示一个@OneToMany
不能属于两个Sites
。
当你这样做时
Condition
你继续entityManager.detach(condition);
持久。您可以尝试使用sites
。