Remove then Query fails in JPA (deleted entity passed to persist)
- by nag
I have two entitys MobeeCustomer and CustomerRegion i want to remove the object from CustomerRegion first Im put join Coloumn in CustomerRegion is null then Remove the Object
from the entityManager but Iam getting Exception
MobeeCustomer:
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;
}
}
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;
}
}
sample code:
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)