Hibernate version: 3
Name and version of the database you are using: Ingres 9.0.4
Hi!
I've got three tables:
Contact,
Email and
Contact_Email
Code:
CREATE TABLE contact (
id INTEGER NOT NULL,
name VARCHAR(60) NOT NULL,
CONSTRAINT pk_contact PRIMARY KEY(id)
);
CREATE TABLE email (
id INTEGER NOT NULL,
address VARCHAR(60) NOT NULL,
CONSTRAINT pk_email PRIMARY KEY(id)
);
CREATE TABLE contact_email (
contact INTEGER NOT NULL,
email INTEGER NOT NULL,
CONSTRAINT pk_contact_email PRIMARY KEY(contact, email),
CONSTRAINT fk_contactemail_2_contact FOREIGN KEY(contact) REFERENCES contact(id),
CONSTRAINT fk_contactemail_2_email FOREIGN KEY(email) REFERENCES email(id)
);
Code:
class Contact {
...
@ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
@JoinTable(name = "contact_email", joinColumns = { @JoinColumn(name = "contact") }, inverseJoinColumns = { @JoinColumn(name = "email") })
public Set<Email> getEmails() {
return this.emails;
}
public void setEmails(Set<Email> emails) {
this.emails = emails;
}
...
}
Code:
class Email {
/** Does not know that Contact exists **/
...
@Id
@Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name = "address", unique = false, nullable = false, insertable = true, updatable = true, length = 60)
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
...
}
Now, when I'm deleting one Email of the contact and update the contact, then the entry in the table
Contact_Email is deleted. But the entry in the table
Email is still there :-/
How can I annotate the
Contact class, that the Email entry in the table
Email will also be deleted?
Thank you!
Best regards Christian