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

zeitiger :

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 modified from code, but I want read access to this property in code.

Vlad Mihalcea :

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

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=441297&siteId=1