I have a class persisted by Hibernate with a derived property isComplete.
@Entity
class Container {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column
private Long id;
@Column private String oneFish;
@Column private String twoFish;
@Column private String redFish;
@Column private String blueFish;
public Boolean isComplete(){
return oneFish != null
&& twoFish != null
&& redFish != null
&& blueFish != null;
}
}
How do I get Hibernate to persist isComplete to the database so that other (non-hibernate) access can see the value?
If you annotated the method with
@Columnit will get persisted (you may have to specify@AccessType/@Accesson the entity)But you shouldn’t do that. Store all the other values and compute the
isCompletewhenever you need it. It is not an expensive operation. You can even ‘cache’ it in a@Transient Booleanproperty, but it need not go the the database.