Remove then Query fails in JPA (deleted entity passed to persist)

Posted by nag on Stack Overflow See other posts from Stack Overflow or by nag
Published on 2012-06-12T10:27:07Z Indexed on 2012/06/12 10:40 UTC
Read the original article Hit count: 272

Filed under:
|
|
|

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)

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate