One-to-One relationship index

Assuming 2 entities are related in one-to-one relationship - Post and PostDetail.

Looking at the DDL Preview in Studio, Post_ID in PostDetail is a FK to Post entity but it’s not indexed. I need to access PostDetail row for each Post row, so will need to have the index on Post_ID in PostDetail. How can i achieve this? Thanks for any advice.

Source of the 2 entities is attached.


@NamePattern("%s|title")
@Table(name = "ONEONE_POST")
@Entity(name = "oneone$Post")
public class Post extends StandardEntity {
    private static final long serialVersionUID = -91728454289812375L;

    @Column(name = "TITLE")
    protected String title;

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "post")
    protected PostDetail postDetail;

    public void setPostDetail(PostDetail postDetail) {
        this.postDetail = postDetail;
    }

    public PostDetail getPostDetail() {
        return postDetail;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

}

@Table(name = "ONEONE_POST_DETAIL")
@Entity(name = "oneone$PostDetail")
public class PostDetail extends StandardEntity {
    private static final long serialVersionUID = 8117802680365648674L;

    @Column(name = "CONTENT")
    protected String content;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "POST_ID")
    protected Post post;

    public void setContent(String content) {
        this.content = content;
    }

    public String getContent() {
        return content;
    }

    public void setPost(Post post) {
        this.post = post;
    }

    public Post getPost() {
        return post;
    }

}

Studio now automatically creates indexes on foreign keys only for many-to-one relationships, which is our fault. We will fix it, thanks for reporting the problem.
Meanwhile, you can add the required index to the init and update scripts manually - between “begin” and “end” comments of the corresponding table.

Thanks for your reply.

I found out another option by setting unique constraint on the FK and Studio will create the index.

Nevertheless, it will be better if it will create the index for FK regardless unique or not.