title: spring boot - calculated field
body: <p>So, I have an entity, that has field start_date (java.util.Date is the type).</p>
  
  <p>I want to have another field, that would automatically populate with integer that corresponds to day of week (as a number 1 for sunday, 2 for monday, etc.) of starting date.</p>
  
  <p>Here's fragment of my entity:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer id;
  
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  @Temporal(TemporalType.DATE)
  private Date start_date;
  </code></pre>
  
  <p>I've tried to add the calculated field in the following way:</p>
  
  <pre><code>@Column(name = "weekday")
  @Formula("(select dayofweek(l.start_date) from Lesson l where l.id = id)")
  private Integer weekDay;
  </code></pre>
  
  <p>However, when looking at the Lesson table in H2 console, there's no such column as "weekday"</p>
  
  <p>I also tried other option - without @Formula annotation and with a setter that takes start_date parameter, but I guess this setter is never called, since the column "weekday" is populated with null.
  Here's the setter I've tried to use as an alternative solution:</p>
  
  <pre><code>    public void setWeekDay(Date start_date) {
      Calendar c = Calendar.getInstance();
      c.setTime(start_date);
      this.weekDay = c.get(Calendar.DAY_OF_WEEK);
  }
  </code></pre>
  
  <p>It's obvious that I'm missing something here, it's probably because I'm still learning Spring boot...</p>
  
  <p>To sum up - I want to have a column in table Lesson, that is calculated from another column of the same table.</p>