Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Last active August 18, 2016 13:30
Show Gist options
  • Save thjanssen/df8a2c70b492a18d709661b96fb5b1b1 to your computer and use it in GitHub Desktop.
Save thjanssen/df8a2c70b492a18d709661b96fb5b1b1 to your computer and use it in GitHub Desktop.
@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = “id”, updatable = false, nullable = false)
private Long id;
@Column
private LocalDate dateOfBirth;
@Formula(value = “date_part(‘year’, age(dateOfBirth))”)
private int age;
public int getAge() {
return age;
}
}
05:35:15,762 DEBUG [org.hibernate.SQL] – select author0_.id as id1_0_, author0_.dateOfBirth as dateOfBi2_0_, author0_.firstName as firstNam3_0_, author0_.lastName as lastName4_0_, author0_.version as version5_0_, date_part(‘year’, age(author0_.dateOfBirth)) as formula0_ from Author author0_ where author0_.id=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment