Hi,

You might want to add @ElementDependent as shown below:

   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, 
      mappedBy = "parent")
   @OrderBy(value = "ordr")
   @ElementDependent
   private List<Child> children = new ArrayList<Child>();

so that when you do:

        em.getTransaction().begin();
        parent.removeChildren();
        em.flush();
        em.getTransaction().commit();

the children will be removed from the database.



--- On Wed, 8/6/08, andiqo <[EMAIL PROTECTED]> wrote:

> From: andiqo <[EMAIL PROTECTED]>
> Subject: Cascade Delete Issue?
> To: [email protected]
> Date: Wednesday, August 6, 2008, 2:37 AM
> Hello,
> 
> I have two entities PARENT & CHILD defined below.
> 
> I try to reset the Parent.children list, or remove the
> parent entity, but
> nothing happen in database for my children (I cant get my
> children anymore
> from Java code (parent.getChildren()), but they are still
> present in
> database even after a commit operation).
> 
> Any idea? It sounds like a OpenJPA issue for me.
> 
> Thanks a lot for our help. Regards,
> 
> Nicolas
> 
> P.S. Tried with openjpa 1.0.3 & 1.1.0
> 
> @Entity
> @Table(name = "PARENT")
> public class Parent {
> 
>    @Id
>    @GeneratedValue(strategy = GenerationType.IDENTITY)
>    @Column(name = "ID")
>    private long id;
> 
>    @Version
>    @Column(name = "VERSION")
>    private int version;
> 
>    @Basic
>    @Column(name = "NAME")
>    private String name;
> 
>    @OneToMany(cascade = CascadeType.ALL, fetch =
> FetchType.LAZY, mappedBy =
> "parent")
>    @OrderBy(value = "ordr")
>    private List<Child> children = new
> ArrayList<Child>();
> }
> 
> @Entity
> @Table(name = "CHILD")
> public class Child {
> 
>    @Id
>    @GeneratedValue(strategy = GenerationType.IDENTITY)
>    @Column(name = "ID")
>    private long id;
> 
>    @Version
>    @Column(name = "VERSION")
>    private int version;
> 
>    @Basic
>    @Column(name = "ORDR")
>    private int ordr;
> 
>    @ManyToOne(fetch = FetchType.EAGER)
>    @JoinColumn(name = "PARENT_ID", nullable =
> false)
>    private Parent parent;
> 
>    @Basic
>    @Column(name = "NAME")
>    private String name;
> }
> -- 
> View this message in context:
> http://n2.nabble.com/Cascade-Delete-Issue--tp675459p675459.html
> Sent from the OpenJPA Users mailing list archive at
> Nabble.com.


      

Reply via email to