the problem is that to persist an instance of PostDetails you need to persist first a Post in order to obtain its id, but you cannot do this without a PostDetails because of the optional = false oprion;
A solution is
public class Post implements Serializable {
@Id
privatelong id;
@MapsId
@JoinColumn(name = "id")
@OneToOne(cascade = {CascadeType.ALL}, optional = false, fetch = FetchType.LAZY)
private PostDetails details;
...
}
public class PostDetails implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
privatelong id;
@OneToOne(mappedBy = "details")
private Post post;
..
}