Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Updating Child Table when updating parent entity(How to manage relationship in Eclipselink(jpa2)?)
Updating Child Table when updating parent entity [message #1182397] Tue, 12 November 2013 01:47 Go to next message
udhyan mahaju is currently offline udhyan mahaju
Messages: 1
Registered: November 2013
Junior Member
public class Legendtype implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id   
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(nullable = false, length = 100)
    private String legendname;
    @Size(max = 500)
    @Column(name = "LEGEND_DESC", length = 500)
    private String legendDesc;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(nullable = false, length = 50)
    private String legendfor;
    @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "legendnameFk", fetch = FetchType.LAZY)
    private List<Legend> legendList;
}




public class Legend implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)   
    private Integer sn;
    @Column(name = "LEGEND_SN")
    private Integer legendSn;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private double lowerrange;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private double upperrange;
    @Size(max = 500)
    @Column(name = "LEGEND_DESC", length = 500)
    private String legendDesc;
    @Size(max = 45)
    @Column(length = 45)
    private String color;
    @JoinColumn(name = "LEGENDNAME_FK", referencedColumnName = "LEGENDNAME", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Legendtype legendnameFk;
}



when I call

public void mergeLegendType(Legendtype lt) {
em.merge(lt);
}

It only updates legendtype but not legend. How to cascade update and delete? I have cascade.all defined.
Re: Updating Child Table when updating parent entity [message #1182981 is a reply to message #1182397] Tue, 12 November 2013 10:02 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1018
Registered: July 2009
Senior Member
The em.merge(lt) call will cascade to any legend referenced within the legendList. Can you give an example of an update that is not being picked up by the merge? What is in the legendList list when you are calling merge?

Previous Topic:JavaDbGenerator error on Luna Release
Next Topic:add list of entities
Goto Forum:
  


Current Time: Tue Sep 02 07:53:27 EDT 2014

Powered by FUDForum. Page generated in 0.02842 seconds