I've got following entity with calculated field isIdle:
@Entity
@Table(name = Customer.TABLE)
public class Customer {
// ...
@JsonIgnore
private static final String IS_IDLE_SQL =
"CASE WHEN (trunc(extract(epoch from now())) - coalesce(last_user_login_time,0) " +
"> 5 * 24 * 3600 ) THEN 1 ELSE 0 END";
@Formula(IS_IDLE_SQL)
private Integer isIdle;
public Integer getIsIdle() {
return isIdle;
}
public void setIsIdle(Integer isIdle) {
this.isIdle = isIdle;
}
}
The field should be 0, if last_user_login_time contains UNIX timestamp which is in the last 5 days, and 1 otherwise.
As it is calculated, I have not corresponding column in my DB table. When I deploy my application, I get the following error:
org.hibernate.HibernateException: Missing column: isIdle in public.customer
at org.hibernate.mapping.Table.validateColumns(Table.java:366)
Why does Hibernate try to find a column for this calculated field? The database uses PostgreSQL.