@@ -0,0 +1,2965 @@
+package com.vladmihalcea.book.hpjp.hibernate.association;%0A%0Aimport com.vladmihalcea.book.hpjp.util.AbstractTest;%0Aimport com.vladmihalcea.book.hpjp.util.providers.Database;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.*;%0Aimport java.util.Date;%0A%0Aimport static org.junit.Assert.assertNotNull;%0A%0A/**%0A * @author Vlad Mihalcea%0A */%0Apublic class OneToOneMapsIdJoinColumnTest 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            PostDetails.class,%0A        %7D;%0A    %7D%0A%0A    @Override%0A    protected Database database() %7B%0A        return Database.MYSQL;%0A    %7D%0A%0A    @Test%0A    public void testLifecycle() %7B%0A        doInJPA(entityManager -%3E %7B%0A            Post post = new Post(%22First post%22);%0A            entityManager.persist(post);%0A        %7D);%0A        doInJPA(entityManager -%3E %7B%0A            Post post = entityManager.find(Post.class, 1L);%0A            PostDetails details = new PostDetails(%22John Doe%22);%0A            details.setPost(post);%0A            entityManager.persist(details);%0A        %7D);%0A%0A        doInJPA(entityManager -%3E %7B%0A            Post post = entityManager.find(Post.class, 1L);%0A            PostDetails details = entityManager.find(PostDetails.class, post.getId());%0A            assertNotNull(details);%0A%0A            entityManager.flush();%0A            details.setPost(null);%0A        %7D);%0A    %7D%0A%0A    @Entity(name = %22Post%22)%0A    @Table(name = %22post%22)%0A    public static class Post %7B%0A%0A        @Id%0A        @GeneratedValue%0A        private Long id;%0A%0A        private String title;%0A%0A        public Post() %7B%7D%0A%0A        public Post(String title) %7B%0A            this.title = title;%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    %7D%0A%0A    @Entity(name = %22PostDetails%22)%0A    @Table(name = %22post_details%22)%0A    public static class PostDetails %7B%0A%0A        @Id%0A        private Long id;%0A%0A        @Column(name = %22created_on%22)%0A        private Date createdOn;%0A%0A        @Column(name = %22created_by%22)%0A        private String createdBy;%0A%0A        @OneToOne%0A        @MapsId%0A        @JoinColumn(name = %22id%22)%0A        private Post post;%0A%0A        public PostDetails() %7B%7D%0A%0A        public PostDetails(String createdBy) %7B%0A            createdOn = new Date();%0A            this.createdBy = createdBy;%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 Date getCreatedOn() %7B%0A            return createdOn;%0A        %7D%0A%0A        public String getCreatedBy() %7B%0A            return createdBy;%0A        %7D%0A%0A        public Post getPost() %7B%0A            return post;%0A        %7D%0A%0A        public void setPost(Post post) %7B%0A            this.post = post;%0A        %7D%0A    %7D%0A%7D%0A

Add new test