users@glassfish.java.net

RE: Cascade delete problem

From: Martin Gainty <mgainty_at_hotmail.com>
Date: Thu, 5 Feb 2009 09:51:50 -0500

This solution is Pure speculation without looking at the DBSchema
//But here is a working EJB3 example that may hellp
//Take a look at the class definition called MAgazine designed for a TableName called MAG_at_Entity@IdClass(Magazine.MagazineId.class)@Table(name="MAG")@DiscriminatorValue("Mag")public class Magazine{//Now we introduce a joined table which will allow communication between MAG and ARTS Tables @OneToMany(cascade={CascadeType.PERSIST,CascadeType.REMOVE})
    @OrderBy
    @JoinTable(name="MAG_ARTS", //Table name is MAG_ARTS
        joinColumns={//The column name here is MAG_ARTS.MAG_ISBN which references MAG.ISBN
            @JoinColumn(name="MAG_ISBN", referencedColumnName="ISBN"),//The column name here is MAG_ARTS.MAG_TITLE which references MAG.TITLE
            @JoinColumn(name="MAG_TITLE", referencedColumnName="TITLE")
        },//This is the reference to IDentifier for ART Table
        inverseJoinColumns=@JoinColumn(name="ART_ID")http://edocs.bea.com/kodo/docs41/full/html/ejb3_overview_mapping_full.htmlHTH
Martin Gainty ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Thu, 5 Feb 2009 04:44:01 -0800> From: glassfish@javadesktop.org> To: users@glassfish.dev.java.net> Subject: Cascade delete problem> > Hi,> > I have a problem with cascading delete. I have two enteties, A and B. One instance of A can have several instances of B in a Collection<B>. The two enteties are joined with a join table that have two columns, the PK from the table of A and B. B is not aware of the relation. This is the source code:> > @Entity> @Table(name="a")> public class A implements Serializable> { > @Id> @GeneratedValue(strategy = GenerationType.IDENTITY)> @Column(name = "id", table = "a")> private int id;> > @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)> @JoinTable(name = "a_b",> joinColumns = {@JoinColumn(name = "a_fk")},> inverseJoinColumns = {@JoinColumn(name = "b_fk")})> private Collection<B> b;> ...> }> > @Entity> @Table(name="b")> public class B implements Serializable> {> @Id> @GeneratedValue(strategy = GenerationType.IDENTITY)> @Column(name = "id", table = "b")> private int id;> ...> }> > When I delete an instance of A(which have a list of B), with EntityManager.remove(A), the correct row is deleted in table a and the corresponding rows are deleted from the join table a_b. BUT the rows in table b, that was belonging to the deleted instance of A are NOT removed. How can this be? What have I done wrong? Or is this a problem with Toplink essentials?> [Message sent by forum member 'nightzero' (nightzero)]> > http://forums.java.net/jive/thread.jspa?messageID=330288> > ---------------------------------------------------------------------> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net> For additional commands, e-mail: users-help@glassfish.dev.java.net>
_________________________________________________________________
Windows Live™: Keep your life in sync.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_022009