Jpa 在PlayFramework 2/Ebean ORM中使用@OneToOne,其中子级和父级共享相同的主键

Jpa 在PlayFramework 2/Ebean ORM中使用@OneToOne,其中子级和父级共享相同的主键,jpa,orm,playframework,one-to-one,ebean,Jpa,Orm,Playframework,One To One,Ebean,有两种模式: 模型/User.java @Entity @Table(name="users") public class User extends Model { @Id public int user_id; public String firstName; public String lastName; @OneToOne @PrimaryKeyJoinColumn public UserProfile profile;

有两种模式:

模型/User.java

@Entity
@Table(name="users")
public class User extends Model
{
    @Id
    public int user_id;
    public String firstName;
    public String lastName;

    @OneToOne
    @PrimaryKeyJoinColumn
    public UserProfile profile;

    public static Finder<Integer,User> find = new Finder<Integer,User>( Integer.class, User.class );
}
@Entity
@Table(name="user_profiles")
public class UserProfile extends Model
{
    @Id
    public int user_id;
    public String bio;

    @OneToOne(mappedBy = "user_id")
    public User user;

    public static Finder<Integer,UserProfile> find = new Finder<Integer,UserProfile>( Integer.class, UserProfile.class );
}
[...]
@OneToOne(mappedBy = "user")
public UserProfile profile;
[...]
[...]
@OneToOne
@JoinColumn(name = "user_id")
public User user;
[...]
以及从用户获取配置文件的相同代码:

User user = User.find.byId(2);
UserProfile profile = UserProfile.find.byId(1);
这会触发异常:

javax.persistence.PersistenceException: Error on models.UserProfile.user. mappedBy property [models.UserBad.user_id]is not a OneToOne?

两个模型如何在Ebean ORM中共享相同的主键,并具有@OneToOne关系?

我发现了它,关联应该是:

模型/User.java

@Entity
@Table(name="users")
public class User extends Model
{
    @Id
    public int user_id;
    public String firstName;
    public String lastName;

    @OneToOne
    @PrimaryKeyJoinColumn
    public UserProfile profile;

    public static Finder<Integer,User> find = new Finder<Integer,User>( Integer.class, User.class );
}
@Entity
@Table(name="user_profiles")
public class UserProfile extends Model
{
    @Id
    public int user_id;
    public String bio;

    @OneToOne(mappedBy = "user_id")
    public User user;

    public static Finder<Integer,UserProfile> find = new Finder<Integer,UserProfile>( Integer.class, UserProfile.class );
}
[...]
@OneToOne(mappedBy = "user")
public UserProfile profile;
[...]
[...]
@OneToOne
@JoinColumn(name = "user_id")
public User user;
[...]
models/UserProfile.java

@Entity
@Table(name="users")
public class User extends Model
{
    @Id
    public int user_id;
    public String firstName;
    public String lastName;

    @OneToOne
    @PrimaryKeyJoinColumn
    public UserProfile profile;

    public static Finder<Integer,User> find = new Finder<Integer,User>( Integer.class, User.class );
}
@Entity
@Table(name="user_profiles")
public class UserProfile extends Model
{
    @Id
    public int user_id;
    public String bio;

    @OneToOne(mappedBy = "user_id")
    public User user;

    public static Finder<Integer,UserProfile> find = new Finder<Integer,UserProfile>( Integer.class, UserProfile.class );
}
[...]
@OneToOne(mappedBy = "user")
public UserProfile profile;
[...]
[...]
@OneToOne
@JoinColumn(name = "user_id")
public User user;
[...]