{"id":204854,"date":"2013-12-06T14:25:03","date_gmt":"2013-12-06T10:25:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=204854"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=204854","title":{"rendered":"<span class=\"post_title\">Spring \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 Hibernate<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u041a\u0430\u043a-\u0442\u043e \u043e\u0431\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0442\u0430\u043a\u0430\u044f \u0442\u0435\u043c\u0430, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Hibernate \u2014 \u044f \u0441\u043c\u043e\u0433 \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d <a href=\"http:\/\/habrahabr.ru\/post\/120631\/\">\u043f\u043e\u0441\u0442<\/a> \u0443\u0436\u0435 \u043f\u043e\u0447\u0442\u0438 \u043c\u043e\u0445\u043d\u0430\u0442\u043e\u0433\u043e \u0433\u043e\u0434\u0430. \u041d\u043e \u0442\u043e \u0430\u0443\u0434\u0438\u0442, \u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 <a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/tree\/562fe4778cc5712d02ccd15fb158314180d0c3f2\">\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c<\/a> \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0441\u0442\u0435\u043d\u0434 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 User \u0438 AnObject, \u0430 \u0442\u0430\u043a \u0436\u0435 DAO-\u0441\u043b\u043e\u0435\u043c \u0434\u043b\u044f \u043d\u0438\u0445.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430 \u2014 \u0432 \u043f\u043e\u043b\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 github  <\/p>\n<pre><code class=\"java\">@Entity @Table(name = &quot;user&quot;) public class User {         @Id         @GeneratedValue         private long id;         @Basic         @Column(name = &quot;username&quot;, updatable = false, unique = true, nullable = false)         private String username;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">@Entity @Table(name = &quot;anObject&quot;) public class AnObject {         @Id         @GeneratedValue         private long id;         @Column         private String value;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/tree\/94a442df6080b842f3bdf3b4fd921b04cc68bd8b\">\u0414\u043e\u0431\u0430\u0432\u0438\u043c<\/a> \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c AnObject \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u2014 \u0434\u0430\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0430\u0432\u0442\u043e\u0440 \u043f\u0440\u0430\u0432\u043a\u0438:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@Embeddable public class LastModified {         @Column         @Temporal(TemporalType.TIMESTAMP)         private Calendar lastUpdated;         @OneToOne         @JoinColumn(name = &quot;lastEditor_id&quot;)         private User lastEditor;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">public interface LastModifiable {         LastModified getLastModified();          void setLastModified(LastModified modified); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">@Entity @Table(name = &quot;anObject&quot;) public class AnObject implements LastModifiable {         @Id         @GeneratedValue         private long id;         @Column         private String value;         @Embedded         private LastModified lastModified;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 <a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/blob\/5b6b9a8329bcd99440f73fdb79546c14d0f290d2\/src\/test\/java\/info\/alenkov\/tutorial\/spring_hibernate_events\/dao\/AnObjectDaoTest.java\">\u043a\u043b\u0430\u0441\u0441<\/a> \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u0421 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0434\u0430\u0442\u0435\/\u0430\u0432\u0442\u043e\u0440\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0440\u0443\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u043d\u043e\u2026 \u043b\u044e\u0434\u0438 \u043c\u044b \u00ab\u043b\u0435\u043d\u0438\u0432\u044b\u0435\u00bb, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438 \u044d\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u2014 \u043f\u0443\u0441\u0442\u044c \u0437\u0430 \u043d\u0430\u0441 \u0432\u0435\u0437\u0434\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 Hibernate. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c Listener \u0438 \u043f\u0440\u043e\u0441\u0438\u043c Hibernate \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f save \u0438\u043b\u0438 update (<a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/commit\/e012134b078987e05d6a323a8eca344110356296\">commit<\/a>):  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@Component public class LastModifiedListener extends DefaultSaveOrUpdateEventListener {         private transient static final Logger LOG = LoggerFactory.getLogger(LastModifiedListener.class.getName());          @Autowired         private UserDao userDao;          @Override         public void onSaveOrUpdate(SaveOrUpdateEvent event) {                 LOG.trace(&quot;object: {}&quot;, event.getObject());                 if (event.getObject() instanceof LastModifiable) {                         LastModified lastModified = new LastModified((User) userDao.get(2));                         ((LastModifiable) event.getObject()).setLastModified(lastModified);                         LOG.trace(&quot;object: {}&quot;, event.getObject());                 }                 super.onSaveOrUpdate(event);         } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">@Component public class HibernateEventWiring {         @Autowired         private SessionFactory sessionFactory;          @Autowired         private LastModifiedListener lastModifiedListener;          @PostConstruct         public void registerListeners() {                 EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(                         EventListenerRegistry.class);                  registry.getEventListenerGroup(EventType.SAVE_UPDATE).prependListener(lastModifiedListener);         } }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p><a name=\"habracut\"><\/a><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u043b\u0441\u044f <a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/commit\/20bb53467df1205f5618235e8a672e894f30a38d\">\u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439<\/a> \u0448\u0442\u0440\u0438\u0445 \u2014 \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f (\u0445\u043e\u0442\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u043f\u0435\u0440\u0432\u0430 \u0442\u0435\u0441\u0442\u044b \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c Listener)<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u2014 \u0443 \u043b\u044e\u0431\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 LastModifiable \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438 \u0432 \u0411\u0414 \u0431\u0443\u0434\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u044f lastUpdated \u0438 lastEditor.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/204854\/\"> http:\/\/habrahabr.ru\/post\/204854\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u041a\u0430\u043a-\u0442\u043e \u043e\u0431\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0442\u0430\u043a\u0430\u044f \u0442\u0435\u043c\u0430, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Hibernate \u2014 \u044f \u0441\u043c\u043e\u0433 \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d <a href=\"http:\/\/habrahabr.ru\/post\/120631\/\">\u043f\u043e\u0441\u0442<\/a> \u0443\u0436\u0435 \u043f\u043e\u0447\u0442\u0438 \u043c\u043e\u0445\u043d\u0430\u0442\u043e\u0433\u043e \u0433\u043e\u0434\u0430. \u041d\u043e \u0442\u043e \u0430\u0443\u0434\u0438\u0442, \u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 <a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/tree\/562fe4778cc5712d02ccd15fb158314180d0c3f2\">\u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c<\/a> \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0441\u0442\u0435\u043d\u0434 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438 User \u0438 AnObject, \u0430 \u0442\u0430\u043a \u0436\u0435 DAO-\u0441\u043b\u043e\u0435\u043c \u0434\u043b\u044f \u043d\u0438\u0445.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u043e\u0436\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0437\u043d\u0430\u0447\u0438\u043c\u044b\u0435 \u043a\u0443\u0441\u043a\u0438 \u043a\u043e\u0434\u0430 \u2014 \u0432 \u043f\u043e\u043b\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 github  <\/p>\n<pre><code class=\"java\">@Entity @Table(name = &quot;user&quot;) public class User {         @Id         @GeneratedValue         private long id;         @Basic         @Column(name = &quot;username&quot;, updatable = false, unique = true, nullable = false)         private String username;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">@Entity @Table(name = &quot;anObject&quot;) public class AnObject {         @Id         @GeneratedValue         private long id;         @Column         private String value;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/tree\/94a442df6080b842f3bdf3b4fd921b04cc68bd8b\">\u0414\u043e\u0431\u0430\u0432\u0438\u043c<\/a> \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c AnObject \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441 \u0434\u0432\u0443\u043c\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u2014 \u0434\u0430\u0442\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0430\u0432\u0442\u043e\u0440 \u043f\u0440\u0430\u0432\u043a\u0438:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@Embeddable public class LastModified {         @Column         @Temporal(TemporalType.TIMESTAMP)         private Calendar lastUpdated;         @OneToOne         @JoinColumn(name = &quot;lastEditor_id&quot;)         private User lastEditor;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">public interface LastModifiable {         LastModified getLastModified();          void setLastModified(LastModified modified); }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">@Entity @Table(name = &quot;anObject&quot;) public class AnObject implements LastModifiable {         @Id         @GeneratedValue         private long id;         @Column         private String value;         @Embedded         private LastModified lastModified;          \/\/ getter and setter }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 <a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/blob\/5b6b9a8329bcd99440f73fdb79546c14d0f290d2\/src\/test\/java\/info\/alenkov\/tutorial\/spring_hibernate_events\/dao\/AnObjectDaoTest.java\">\u043a\u043b\u0430\u0441\u0441<\/a> \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u0421 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0434\u043b\u044f \u0432\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0434\u0430\u0442\u0435\/\u0430\u0432\u0442\u043e\u0440\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0440\u0443\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u043d\u043e\u2026 \u043b\u044e\u0434\u0438 \u043c\u044b \u00ab\u043b\u0435\u043d\u0438\u0432\u044b\u0435\u00bb, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438 \u044d\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0443 \u2014 \u043f\u0443\u0441\u0442\u044c \u0437\u0430 \u043d\u0430\u0441 \u0432\u0435\u0437\u0434\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 Hibernate. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c Listener \u0438 \u043f\u0440\u043e\u0441\u0438\u043c Hibernate \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f save \u0438\u043b\u0438 update (<a href=\"https:\/\/github.com\/BorzdeG\/info.alenkov.tutorial.spring-hibernate-events\/commit\/e012134b078987e05d6a323a8eca344110356296\">commit<\/a>):  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@Component public class LastModifiedListener extends DefaultSaveOrUpdateEventListener {         private transient static final Logger LOG = LoggerFactory.getLogger(LastModifiedListener.class.getName());          @Autowired         private UserDao userDao;          @Override         public void onSaveOrUpdate(SaveOrUpdateEvent event) {                 LOG.trace(&quot;object: {}&quot;, event.getObject());                 if (event.getObject() instanceof LastModifiable) {                         LastModified lastModified = new LastModified((User) userDao.get(2));                         ((LastModifiable) event.getObject()).setLastModified(lastModified);                         LOG.trace(&quot;object: {}&quot;, event.getObject());                 }                 super.onSaveOrUpdate(event);         } }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"java\">@Component public class HibernateEventWiring {         @Autowired         private SessionFactory sessionFactory;          @Autowired         private LastModifiedListener lastModifiedListener;          @PostConstruct         public void registerListeners() {                 EventListenerRegistry registry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry().getService(                         EventListenerRegistry.class);                  registry.getEventListenerGroup(EventType.SAVE_UPDATE).prependListener(lastModifiedListener);         } }<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-204854","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/204854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=204854"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/204854\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=204854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=204854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=204854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}