2012-12-31

Hibernate write-only properties

How to implement?

Easily… simply ignore the value when being set.

@Entity
public class Invoice {

    private List<Items> items = new ArrayList();

    @Column(name="total")
    public int getTotal(){
      // Sum item's price...
      return ...
    }

    public void setTotal( int total ){
      // Ignore.
    }

}

Note that this will have the side effect of re-computing every time Hibernate saves the data.


0