How to define database generated column values as readonly fields in JPA and Hibernate?

With MariaDB 10.2 it’s possible to define default value for Datetime e.g. created and lastModified.

How I should access this columns as readonly field? Because this values should only be under control of the database and should not be modify from code, but I want read access to this property in code.

It’s simple. Just set the insertable and updatable attributes to false.

@Column(
    name = "created_on", 
    insertable = false, 
    updatable = false
)
private Timestamp createdOn;

You can use:

@Column(updatable=false, insertable=false)
private YourType fied;

Where the @Column is used to specify the mapped column for a persistent property or field. In particular it is javax.persistence.Column.