3
My table in the database has a column that is automatically populated by the database itself.
This table is mapped as an annotated class with @Entity, called EntidadeA
. The column that is automatically populated is mapped to a property annotated with @Column, called prop1
.
When executing EntityManager.persist(objeto)
, with the property prop1
= null
, Hibernate performs a INSERT INTO tb... (coluna_prop1, ...) values (NULL, ...)
in the database.
At that moment the database arrow a YYY value in the column_prop1.
Question: How to make Hibernate reread from the database, immediately after the persist, the value of a column?
Note: Currently running EntityManager.refresh(objeto)
right after persist() --- it works, but this makes Hibernate re-read all the database properties (ie. inefficient).
thiagoinu, here’s how to control the "item 1" of the other answer
– SparK
Spark, actually this option does not cause the application to change the database. It is the counterpart of item 2, doing the automatic "refresh" of the marked columns for pre-configured simple types (think about getGeneratedKeys() of the JDBC).
– Anthony Accioly