Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 345
zeitiger Avatar asked Aug 01 '17 06:08

zeitiger


1 Answers

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

@Column(
    name = "created_on", 
    insertable = false, 
    updatable = false
)
private Timestamp createdOn;
like image 173
Vlad Mihalcea Avatar answered Oct 27 '22 11:10

Vlad Mihalcea