-->
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: @ManyToOne need to delete referenced foreign key - ERROR?
PostPosted: Wed Jan 27, 2010 10:04 am 
Newbie

Joined: Wed Jan 27, 2010 9:58 am
Posts: 1
Hello

I have to classes: NewsVO and FileVO, which looks like:

Code:
package vo;
import javax.persistence.*;

@Entity
@Table(name="newsdb")
public class NewsVO {
   private long id;
   private FileVO image;

   @Id
   @GeneratedValue
   @Column(name="ID")
   public long getId() {
      return id;
   }

   public void setId(long id) {
      this.id = id;
   }
   
   @ManyToOne()
   @JoinColumn(name = "filedb_ID")
   public FileVO getImage() {
      return image;
   }

   public void setImage(FileVO image) {
      this.image = image;
   }
}


And:

Code:
package vo;
import javax.persistence.*;

@Entity
@Table(name="filedb")
public class FileVO {

   private int id;
   private String filename;
   
   @Id
   @GeneratedValue
   @Column(name="ID")
   public int getId() {
      return id;
   }
   
   public void setId(int id) {
      this.id = id;
   }

   @Column(name="FILE_NAME")
   public String getFilename() {
      return filename;
   }
   
   public void setFilename(String filename) {
      this.filename = filename;
   }
}


A NewsVO object can be deleted without deleting the referenced FileVO or throwing any errors. But the FileVO object cannot be deleted without getting this error:

java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`backend`.`newsdb`, CONSTRAINT `FKC17C2E9112C306AA` FOREIGN KEY (`filedb_ID`) REFERENCES `filedb` (`ID`))

I'm not sure whether @ManyToOne is correct to use in this scenario, if not please guide me in the right direction, or help me alter the current code so that I am able to delete the FileVO, and have it remove all references to it on NewsVO objects persisted to the database.

Thanks :-)


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.