I’d like to add some additional methods to a Seam entity. These methods don’t have a own column in the database. They just format and combinate some columns.
@Entity
@Table(name = "event", schema = "public")
public class Event implements java.io.Serializable {
// [...]
@Column(name = "status", nullable = false, length = 13)
@NotNull
@Length(max = 13)
private String status;
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
public String getSpecialStatus() { // not allowed as there is no setter and no column 'specialStatus'
return someValue;
}
// [...]
}
This code throws the following exception:
javax.persistence.PersistenceException: org.hibernate.PropertyNotFoundException: Could not find a setter for property specialStatus in class foobar.entity.Event
I tried to add the following setter:
private void setSpecialStatus(String status){
throw new NotImplementedException();
}
The exception changes to:
javax.persistence.PersistenceException: org.hibernate.HibernateException: Missing column: specialStatus in public.event
Does anyone know if there is a way to solve this problem? Or is it bad practice to add additional methods to an entity? (If so, how should I implement it?)
I’m not sure how this will interact with your use of annotations on fields, but if you annotate your getters, you could use the @Transient annotation to tell Hibernate this is not to be persisted.