I have a Company class:

  | public class Company implements Serializable {
  | 
  | ....
  | 
  | @OneToMany (mappedBy="company", cascade=CascadeType.ALL)
  |     @JoinColumn(name="COMPANY_ID")
  |     private List<Address> addresses = new ArrayList<Address>();
  | ...
  | }
  | 

The intention is a company can have one to many addresses.

Here is the Address:


  | public class Address implements Serializable {
  | ....
  | 
  | @ManyToOne
  | private Company company;
  | 
  | ...
  | }
  | 

The behavior I want is if a Company is deleted, all the associated Addresses 
should be removed as well.

However when I delete a Company I get a constraint violation:

  | com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: 
Cannot delete or update a parent row: a foreign key constraint fails 
(`db`.`address`, CONSTRAINT `FK1ED033D44C674D5C` FOREIGN KEY (`company_id`) 
REFERENCES `company` (`id`))
  | 

I thought the cascade=CascadeType.ALL in the Company class would give me this.

What am I doing wrong?

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4228062#4228062

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4228062
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to