tibtof
tibtof

Reputation: 7957

Modifying a collection makes the entity dirty

I have an entity defined as follows

@Entity(name = "Report")
@Table(name = "REPORTS")
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, selectBeforeUpdate = true)
public class Report implements java.io.Serializable        {

    /* other fields, getters and setters*/
    @Column(name = "UPD_TIMESTAMP")
    @Version
    private Long updTimestamp;

    @OneToMany(mappedBy = "report", fetch = FetchType.LAZY)
    private Collection<ReportItem> reportItems = new ArrayList<ReportItem>();

    public Collection<ReportItem> getReportItems() {
       return reportItems;
    }

    public void setReportItems(Collection<ReportItems> reportItems) {
       this.reportItems = reportItems;
    }
}

The problem is that when I modify something in reportItems, the Report entity becomes dirty and there is always an update that increments the version field only.

I know abut @OptimisticLock(excluded=true), but i'm stuck to Hibernate 3.2.0 GA and this annotation isn't available. Is there any workaround to this feature that I can use with Hibernate 3.20 GA?

Upvotes: 2

Views: 1988

Answers (1)

siebz0r
siebz0r

Reputation: 20329

Take a look at the inverse keyword, maybe this can provide a solution. Here it is explained.

Edit: Turns out this is expected behavior. See this question

Upvotes: 1

Related Questions