[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Cascade delete not desired, on a ManyToMany relation
|
Dear Guy.
Sorry for not having properly explained. I'll try again.
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.
I hope I explained better.
Guy thank you very much for your interest and your time.
Guy Pelletier wrote:
>
> Hi,
>
> I may have misunderstood your problem, but seems like correct behavior
> and what you're requesting would actually be incorrect behavior. By
> deleting a 'desease', you are removing references to it from patient via
> the 'patient_desease' table and EclipseLink is correctly not cascade
> deleting the patient.
>
> Having a fk in patient_desease to a now removed desease would be an error.
>
> Cheers,
> Guy
>
> On 03/06/2011 6:48 AM, nocknock wrote:
>> 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 "patiente_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?
>>
>> 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.
>>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>
--
View this message in context: http://old.nabble.com/Cascade-delete-not-desired%2C-on-a-ManyToMany-relation-tp31764465p31766083.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.