I have tested with Hibernate 5.0.4 and randomly with 4.3.11. The issue is reproducible in both these versions. I believe, we might be able to reproduce this issue with some other version as well.
I have two entities Post and PostDetails that are mapped as OneToOne with shared primary key, optional=false and id generator strategy set as IDENTITY/AUTO. When I try to persist the Post entity it fails with throwing exception.
Assuming we have following entities Post and PostDetails mapped as OneToOne with shared primary key, optional=false and id generator strategy set as IDENTITY/AUTO as below
{code:java} @Entity public class Post implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @OneToOne(mappedBy="post", cascade = { CascadeType.ALL }, optional=false) private PostDetails details; public long getId() { return id; } public PostDetails getDetails() { return details; } public void addDetails(PostDetails details) { this.details = details; details.setPost(this); }