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 :-)