Skip to main content

[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

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.


Back to the top