Skip to content
Advertisement

JPA does not return default value after saving

I faced a problem. A have an entity:

JavaScript

DDL of the related table:

JavaScript

I have such logic:

JavaScript

Field dateCreate is set by DB function now() but it is not returned by JPA in created entity.

Does anyone know how to solve this problem? Without using Hibernate or Spring specific tools. Just JPA.

Advertisement

Answer

You need to refresh the data after saving it to the database and to get the latest state of the object, as entityManager.refresh(createdUser)

You can use it as mentioned below.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement