I'm using JPA2 and Hibernate implementation.
I've got simple mapping like this:
@Entity
class Topic {
@Id
@GeneratedValue(strategy = IDENTITY)
int id;
@OneToOne(cascade = ALL)
@JoinColumn(name = "id_poll")
private Poll poll;
}
@Entity
class Poll {
@Id
@GeneratedValue(strategy = IDENTITY)
int id;
}
Now, when I delete a Poll object which is also in Topic I get an error.
java.sql.SQLException: Integrity constraint violation FKCC42D924982D3F4B table: TOPICS in statement [delete from polls where id=?]
I understand that it is because I can't delete the Poll record if it has references in another table. How can I solve this problem? Do I have to manually set poll = null in a Topic table or is there a better solution?