-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate does not delete everything
PostPosted: Thu May 24, 2007 5:19 am 
Beginner
Beginner

Joined: Wed Jun 07, 2006 6:11 am
Posts: 20
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:15 am 
Beginner
Beginner

Joined: Fri Aug 12, 2005 7:05 am
Posts: 25
Location: TamilNadu
Post your mapping files and codes between session.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 7:10 am 
Beginner
Beginner

Joined: Wed Jun 07, 2006 6:11 am
Posts: 20
Code:
contact.getEmails().remove(email);
EntityManager.merge(contact);


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

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.