0

What's the correct way to create bidirectional 1to1 mapping using Embeddable annotation? This one throws error "EmpId has no persistent id property: Emp.id"

@Entity
public class Per implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "per_id")
    private Long id;
 
    @OneToOne
    @JoinColumn(name = "per_id", referencedColumnName = "emp_id")
    private Emp emp;
 
}
 
@Embeddable
public class EmpId implements Serializable {
    private static final long serialVersionUID = 1L;
 
    @OneToOne(mappedBy = "emp")
    private Per per;
 
}
 
@Entity
public class Emp implements Serializable {
    @EmbeddedId
    private EmpId id;
}

I'd like to operate entities like

per.getEmp();
emp.getId().getPer();

0 Answers0