hi guys
i have a question: Following scenario:
table1: Person (id , name) => pk: id
table2: Person_Email(id, email) => pk: id, email with id also being a fk to person
my entities are like this
Code:
@Entity
@Table(name="person")
public class Person implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_seq")
@SequenceGenerator(name = "person_seq", sequenceName = "person_seq", allocationSize = 1)
@Column(name="id")
private int id;
@Column(name="name", length=40)
private String name;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="id")
private List<PersonEmail> emails;
}
and the other one
Code:
@Entity
@Table(name="person_email")
public class PersonEmail implements Serializable{
private static final long serialVersionUID = 1L;
@Id
private Pk pk;
}
Pk is a composite primary key class: very simple also:
Code:
@Embeddable
public class Pk implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name="id")
private int id;
@Column(name="email")
private String email;
}
now everything works fine... i can create a new Person object ... add email addresses save them, update them but then ...
when i try to delete an email address from the collection hibernate for some reason tries to just "remove the link" by updating the id of person_email to null... which is of course not possible since its part of the primary key
here the query that is being issued:
Hibernate:
/* delete one-to-many row com.domain.Person.emails */ update
person_email
set
id=null
where
id=?
and email=?
and id=?
here is the error
java.sql.BatchUpdateException: ORA-01407: cannot update ("MYDB"."PERSON_EMAIL"."ID") to NULL
now the question... is there a way to tell hibernate to force a delete... not an update... ?
thank you