@@ -0,0 +1,3032 @@
+package com.vladmihalcea.book.hpjp.hibernate.association;%0A%0Aimport com.vladmihalcea.book.hpjp.util.AbstractTest;%0Aimport org.junit.Test;%0A%0Aimport javax.persistence.*;%0Aimport java.util.Date;%0Aimport java.util.List;%0A%0Aimport static org.junit.Assert.assertNotNull;%0A%0A/**%0A * @author Vlad Mihalcea%0A */%0Apublic class BidirectionalOneToOneNPlusOneTest 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    @Test%0A    public void test() %7B%0A        doInJPA(entityManager -%3E %7B%0A            for (int i = 0; i %3C 3; i++) %7B%0A                Post post = new Post(String.format(%22Post nr. %25d%22, i));%0A                post.setDetails(new PostDetails(%22Excellent!%22));%0A%0A                entityManager.persist(post);%0A            %7D%0A        %7D);%0A%0A        doInJPA(entityManager -%3E %7B%0A            List%3CPost%3E posts = entityManager.createQuery(%0A                %22select p from Post p %22 +%0A                %22where p.title like 'Post nr.%25'%22, Post.class)%0A            .getResultList();%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        @OneToOne(mappedBy = %22post%22, cascade = CascadeType.ALL, fetch = FetchType.LAZY)%0A        private PostDetails details;%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%0A        public PostDetails getDetails() %7B%0A            return details;%0A        %7D%0A%0A        public void setDetails(PostDetails details) %7B%0A            this.details = details;%0A            details.setPost(this);%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        @GeneratedValue%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(fetch = FetchType.LAZY)%0A        @MapsId%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 @OneToOne N+1 query issue test