@@ -0,0 +1,2612 @@
+package com.vladmihalcea.book.hpjp.hibernate.mapping;%0A%0Aimport com.vladmihalcea.book.hpjp.util.AbstractTest;%0Aimport org.hibernate.annotations.DynamicUpdate;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.*;%0Aimport java.sql.Timestamp;%0Aimport java.time.format.DateTimeFormatter;%0A%0A/**%0A * @author Vlad Mihalcea%0A */%0Apublic class DynamicUpdateTest extends AbstractTest %7B%0A%0A    @Override%0A    protected Class%3C?%3E%5B%5D entities() %7B%0A        return new Class%3C?%3E%5B%5D %7B%0A            Post.class%0A        %7D;%0A    %7D%0A%0A    @Test%0A    public void test() %7B%0A%0A        doInJPA(entityManager -%3E %7B%0A            Post post = new Post();%0A            post.setId(1L);%0A            post.setTitle(%22High-Performance Java Persistence%22);%0A            entityManager.persist(post);%0A        %7D);%0A        doInJPA(entityManager -%3E %7B%0A            Post post = entityManager.find(Post.class, 1L);%0A            LOGGER.info(%22Fetched post: %7B%7D%22, post);%0A            post.setScore(12);%0A        %7D);%0A    %7D%0A%0A    @Entity(name = %22Post%22)%0A    @Table(name = %22post%22)%0A    @DynamicUpdate%0A    public static class Post %7B%0A%0A        @Id%0A        private Long id;%0A%0A        private String title;%0A%0A        private long score;%0A%0A        @Column(name = %22created_on%22, nullable = false, updatable = false)%0A        private Timestamp createdOn;%0A%0A        @Transient%0A        private String creationTimestamp;%0A%0A        public Post() %7B%0A            this.createdOn = new Timestamp(System.currentTimeMillis());%0A        %7D%0A%0A        public String getCreationTimestamp() %7B%0A            if(creationTimestamp == null) %7B%0A                creationTimestamp = DateTimeFormatter.ISO_DATE_TIME.format(%0A                    createdOn.toLocalDateTime()%0A                );%0A            %7D%0A            return creationTimestamp;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return String.format(%0A                %22Post%7B%5Cn%22 +%0A                %22  id=%25d%5Cn%22 +%0A                %22  title='%25s'%5Cn%22 +%0A                %22  score=%25d%5Cn%22 +%0A                %22  creationTimestamp='%25s'%5Cn%22 +%0A                '%7D', id, title, score, getCreationTimestamp()%0A            );%0A        %7D%0A%0A        public Long getId() %7B%0A            return id;%0A        %7D%0A%0A        public void setId(Long id) %7B%0A            this.id = id;%0A        %7D%0A%0A        public String getTitle() %7B%0A            return title;%0A        %7D%0A%0A        public void setTitle(String title) %7B%0A            this.title = title;%0A        %7D%0A%0A        public long getScore() %7B%0A            return score;%0A        %7D%0A%0A        public void setScore(long score) %7B%0A            this.score = score;%0A        %7D%0A%0A        public Timestamp getCreatedOn() %7B%0A            return createdOn;%0A        %7D%0A    %7D%0A%7D%0A

Add DynamicTest