| In the following example:
@Entity(name = "PostDetails")
@Table(name = "post_details")
public class PostDetails {
@Id
private Long id;
@Column(name = "created_on")
private Date createdOn;
@Column(name = "created_by")
private String createdBy;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(foreignKey = @ForeignKey(name = "fk_post"))
@MapsId
private Post post;
public PostDetails() {}
public PostDetails(String createdBy) {
createdOn = new Date();
this.createdBy = createdBy;
}
the
@JoinColumn(foreignKey = @ForeignKey(name = "fk_post"))
has ho effect but I expect the foreign key to get the custom name "fk_post". Instead the FK name is randomly generated. The one-to-one relationship is uni-directional. The code is taken from "The best way to map a @OneToOne relationship with JPA and Hibernate" post (section "The most efficient mapping"). I also created question on SO. |