Generate Persistence Mapping by Database Structure for @OneToOne Mapping Not Working?

I am trying to understand why the Generate Persistence Mapping by Database Structure is not mapping @OneToOne (bi-directional) on the entities.

For my database structure, I've tried a foreign key from one table referencing the other and vice versa, and I've also tried foreign keys in both tables together referencing one another and it always maps @ManyToOne. I would have thought setting the user_id and user_detail_id to unique in their respective tables would suggest a @OneToOne mapping, but that's not the case.

I don't know if it's a database structure, a mapping issue, or both. Any suggestions on what I could be missing?

Below is an example of building unique foreign keys in both tables and their mapping:   

Table Structure

create table user
(
    id             int unsigned auto_increment
        primary key,
    user_detail_id int unsigned null,
    first_name     varchar(100) null,
    last_name      varchar(100) null,
    constraint user_user_detail_id_uindex
        unique (user_detail_id),
    constraint user_user_detail_id_fk
        foreign key (user_detail_id) references user_detail (id)
);


create table user_detail
(
    id      int unsigned auto_increment
        primary key,
    user_id int unsigned null,
    ssn     varchar(11)  null,
    constraint user_detail_user_id_uindex
        unique (user_id),
    constraint user_detail_user_id_fk
        foreign key (user_id) references user (id)
);

Entity Mappings

@Entity
@Table(name = "user", schema = "video", catalog = "")
public class UserEntity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id", nullable = false)
    private int id;
    @Basic
    @Column(name = "user_detail_id", nullable = true)
    private Integer userDetailId;
    @Basic
    @Column(name = "first_name", nullable = true, length = 100)
    private String firstName;
    @Basic
    @Column(name = "last_name", nullable = true, length = 100)
    private String lastName;
    @ManyToOne
    @JoinColumn(name = "user_detail_id", referencedColumnName = "id")
    private UserDetailEntity userDetailByUserDetailId;




@Entity
@Table(name = "user_detail", schema = "video", catalog = "")
public class UserDetailEntity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column(name = "id", nullable = false)
    private int id;
    @Basic
    @Column(name = "user_id", nullable = true)
    private Integer userId;
    @Basic
    @Column(name = "ssn", nullable = true, length = 11)
    private String ssn;
    @ManyToOne
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    private UserEntity userByUserId;

 

0

Hello,

Sorry, it is not available in Generate Persistence Mapping functionality. Please see IDEA-98546.

Currently, we are not working to improve that part of functionality for JPA/Hibernate mappings, but we definetly keep this issue in mind.

0

请先登录再写评论。