Initializing sleep mail

I would like to initialize the members of the persistent object class as soon as Hibernate loads the object from the database.

How can i do this?

In particular: in the next stored object, I would like to initialize the datetime zone

class Schedule {

    Calendar date
    TimeZone tz;

}

I cannot do this in the constructor because hibernate will use setters to initialize the object. I cannot do this in setters because I cannot rely on the initialization order.

+3
source share
4 answers

You need to register an event listener after loading; it will be called after loading the object so that you can perform any subsequent processing.

JPA (Hibernate EntityManager), @PostLoad.

Hibernate PostLoadEventListener .

+6

.


@Basic(fetch=FetchType.EAGER)
Calendar date;

0

? , @Transient :

private Calendar date = Calendar.getInstance();
0

, , .

, , . UTC, java .

.

0

Source: https://habr.com/ru/post/1721987/


All Articles