Cascade delete not desired, on a ManyToMany relation [message #676245] |
Fri, 03 June 2011 11:20 |
nocknock Messages: 12 Registered: June 2011 |
Junior Member |
|
|
Hi friends.
I'm newer on JPA, and i've started with EclipseLink 2.2 and Glassfish 3.1.1.
I have 2 entities, with a relationship ManyToMany between "patient" and "desease", maped from a postgresql database with 3 tables (desease, patient, patient_desase), and "patient_desase" have a foreign key to "desase" that restrict deletes from that table.
My problem is, when i delete a register in table "desease", is deleted on registers in "patient_desease" too. And i don't want that behavior, i don't want that registers on table "patient_desease" be deleted automatically.
What am I doing wrong?
What I want is that when you try to delete a disease suffered by one patient (assigned to this patient on the table "patient_desase"), the erase operation is canceled ( arise and exception for violation of a foreign key), and warning the user that can not be deleted until remove the assignment of this disease to the patient.
I want block erase actions of diseases while they are assigned to patients.
These are the entities.
@Entity
@Table(name = "desease")
@XmlRootElement
public class Desease implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "code")
private Integer code;
@Size(max = 50)
@Column(name = "name")
private String name;
@JoinTable(name = "patient_desease", joinColumns = {@JoinColumn(name = "cod_des",
referencedColumnName = "code")}, inverseJoinColumns = {@JoinColumn(name = "cod_pat",
referencedColumnName = "code")})
@ManyToMany
private List<Patient> patientList;
....
}
@Entity
@Table(name = "patient")
@XmlRootElement
public class Patient implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "code")
private Integer code;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 40)
@Column(name = "name")
private String name;
.....
@ManyToMany(mappedBy = "deseaseList")
private List<Desease> deseaseList;
.....
}
Thank you, very much.
[Updated on: Fri, 03 June 2011 15:05] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.22887 seconds