JPA association table is not deletable

Posted by Marcel on Stack Overflow See other posts from Stack Overflow or by Marcel
Published on 2010-03-19T21:03:42Z Indexed on 2010/03/20 20:11 UTC
Read the original article Hit count: 507

Filed under:
|

Hi

I have a problem with JPA (EclipseLink). I am not able to delete a association table. This is the situation:

  • Product 1:n to ProductResource
  • Resource 1:n to ProductResource

I first set the product and resource attributes of ProductResource. If I then try to delete the ProductResource object nothing happens (no sql is generated - no exception). If I comment out both OneToMany annotations in ProductResource I can delete the object. I can also delete the object when product and resource attributes are not set. If I comment out only the annotation above the ressource attribut the ProductResource object gets deleted upon the deletion of the product object (cascade=CascadeType.ALL). I hope someone could give me a hint. Thank you.

Product Resource:

public class ProductResource implements Serializable {
 @ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.MERGE)
 private Product product;

 @ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.MERGE)
 private Resource resource;

Product:

public class Product implements Serializable {

 @OneToMany(mappedBy="product", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
 private List<ProductResource> productResources = new ArrayList<ProductResource>();

Resource:

public class Resource implements Serializable {

 @OneToMany(mappedBy="resource", fetch=FetchType.EAGER, cascade=CascadeType.ALL)
 private List<ProductResource> productResources = new ArrayList<ProductResource>();

Greetings Marcel

© Stack Overflow or respective owner

Related posts about jpa

Related posts about eclipselink