Data Loss when using getter on a lazy loaded @OneToMany Relationship

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Data Loss when using getter on a lazy loaded @OneToMany Relationship


I have a Problem with a @OneToMany Relationship.

Java SE, no Weaving (no javaagent started), Eclipselink 2.5.2 (the one
shipped with NetBeans IDE 8.1)

Now I have the following Code sequence:

Master master = em.find(Master.class, 0);
master.setLastChange(new Date());
List<Detail> someDetails = master.getDetails();
if (!em.contains(master)) {
        master = (Master) em.merge(master);

And reproducable, Master.lastChange keeps null on Database. In Debugger,
the lastChange value vanishes on the master.getDetails() Call (looks
like it gets replaced by the value previously in the database).

According to my knowledge, even changes before the Start of the
Transaction should be written to Database on flush/commit.

What is wrong here and how can I get it to work?

My Entity Beans (a little bit simplified) are:

@Table(name = "MASTER")
public class Master implements Serializable {

        public static final long serialVersionUID = 1L;

        @Basic(optional = false)
        @SequenceGenerator(name = "MASTER_SEQ", sequenceName ="MASTER_SEQ",
allocationSize = 1)
        @GeneratedValue(generator = "MASTER_SEQ", strategy =
        @Column(name = "ID", nullable = false)
        private Long id;

        @Column(name = "LASTCHANGE")
        private Date lastChange;

        @OneToMany(mappedBy = "master", cascade = CascadeType.ALL,
orphanRemoval = ture, fetch = FetchType.LAZY)
        private List<Detail> details;

/* standards setters and getters for all Attributes; id has no setter;
just one example to clarify: */

        public Date getLastChange() {
                return lastChange;

        public void setLastChange(Date lastChange) {
                this.lastChange = lastChange;


@Table(name = "DETAIL")
public class Detail implements Serializable {

        public static final long serialVersionUID = 1L;

        private DetailPK detailPK;

        @ManyToOne(cascade = CascadeType.ALL)
        @JoinColumn(name = "MASTER_ID", referencedColumnName = "ID", nullable =
false, insertable = true, updatable = true)
        Master master;

        @Column(name = "CONTENT")
        private String content;

/* standard Setters and getters also here */


public class DetailPK implements Serializable {

        public static final long SerialVersionUID = 1L;

        @Basic(optional = false)
        @Column(name = "MASTER_ID", nullable = false, updatable = false,
insertable = false)
        private Long masterId;

        @Basic(optional = false)
        @Column(name = "DETAIL_ID")
        private Long detailId;

/* and again, we have standard setters and getters */


Erhard Schwenk

Akkordeonjugend Baden-W├╝rttemberg - http://www.akkordeonjugend.de/
APAYA running System - http://www.apaya.net/
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit