-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Foreign Key error when deleting one side of a M-M assn.
PostPosted: Thu May 21, 2009 4:11 pm 
Beginner
Beginner

Joined: Fri Jun 10, 2005 2:22 pm
Posts: 27
Hi folks,

I'm using Hibernate 3.3.2.GA Entity Manager with JPA. My database is MySQL 5.0. I have an association between a Pricelist and a Product called ProductPrice. A straight-up Many-to-Many association wouldn't have given us the opportunity to add properties at the association point. (that I'm aware of) So, we have instead defined the two One-to-Many relationships. Here are some excerpts from the classes in question. (Note that Product has no knowledge of the ProductPrice entities that he participates in. This is by design.)

Product entity:
Code:
   @Column(name="name", nullable=false, length=50)
   private String name;
   
   @Column(name="display_name", nullable=false, length=50)
   private String displayName;
   
   @Column(name="code", nullable=false, length=25)
   private String code;
   
   @ManyToOne
   @JoinColumn(name="product_type_id")
   private ProductType productType;
   
   @ManyToOne
   private Customer customer;


Pricelist entity:
Code:
    @Column(name="name", nullable=false, length=50)
    private String name;

    @ManyToOne
    private Customer customer;

    @OneToMany(mappedBy="pricelist", cascade={CascadeType.ALL})
    @JoinColumn(name="pricelist_id")
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private Set<ProductPrice> productPrices = new HashSet<ProductPrice>();


ProductPrice entity:
Code:
    @ManyToOne(optional=false)
    private Product product;
   
    @ManyToOne(optional=false)
    private Pricelist pricelist;


The problem - when I attempt to delete a Pricelist, I get a foreign key violation exception on the ProductPricelist entity. Other entities in my application that have a One-to-Many relationship are functioning properly and are defined in a way similar to the Pricelist->ProductPrice relationship. I can only assume that the problem stems from the other side of this Many-to-Many association.

Can anyone offer any possibilities?
Thanks,
Dave


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.