我有两个实体 MobeeCustomer 和 CustomerRegion 我想首先从 CustomerRegion 中删除对象我将 CustomerRegion 中的 join Coloumn 为 null 然后从 entityManager 中删除对象但我得到了异常
Mobee客户:
public class MobeeCustomer implements Serialization{ private Long id; private String custName; private String Address; private String phoneNo; private Set<CustomerRegion> customerRegion = new HashSet<CustomerRegion>(0); @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "mobeeCustomer") public Set<CustomerRegion> getCustomerRegion() { return CustomerRegion; } public void setCustomerRegion(Set<CustomerRegion> customerRegion) { CustomerRegion = customerRegion; } }
客户区域
public class CustomerRegion implements Serializable{
private Long id;
private String custName;
private String description;
private String createdBy;
private Date createdOn;
private String updatedBy;
private Date updatedOn;
private MobeeCustomer mobeeCustomer;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MOBEE_CUSTOMER")
public MobeeCustomer getMobeeCustomer() {
return mobeeCustomer;
}
public void setMobeeCustomer(MobeeCustomer mobeeCustomer) {
this.mobeeCustomer = mobeeCustomer;
}
}
示例代码:
if (doUpdateRegion.getStatus().equals(UserOperations.DELETE.getType())) {
custEntity = getEntityManager().find(CustomerRegion.class,doUpdateRegion.getId());
BeanUtils.copyProperties(custEntity, doUpdateRegion);
deletedRegionsList.add(custEntity);
}
for (CustomerRegion region : deletedRegionList) {
region.setMobeeCustomer(null);
getEntityManager().remove(region);
}
StackTrace:
please suggest me how to remove the CustomerRegion Object I am getting Exception
javax.persistence.EntityNotFoundException: deleted entity passed to persist: [com.manam.mobee.persist.entity.CustomerRegion#<null>]
15:46:34,614 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:613)
15:46:34,614 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:299)
15:46:34,614 ERROR [STDERR] at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:92)
15:46:34,614 ERROR [STDERR] at org.jboss.seam.framework.EntityHome.update(EntityHome.java:64)