I am using @OneToOne Relation ship(Bi-directional) Parent @Entity @Table(name="student") public class Student { @Id @GeneratedValue
private int sno;
@Column(name="name") private String name; @OneToOne(cascade = CascadeType.ALL) @JoinColumn(name="sno",unique=true,nullable=false) private Address address; //setters and getters
Child: @Id @GeneratedValue(generator="gen") @GenericGenerator(name = "gen", strategy = "foreign",parameters= @Parameter(name = "property", value = "student"))
private int sno;
@Column(name="state") private String state; @OneToOne(cascade=CascadeType.ALL) @PrimaryKeyJoinColumn private Student student; //setters and getters .when i am calling save(Parent) it throws the following exception:: exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [info.inetsolv.models.Address.student] org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822) javax.servlet.http.HttpServlet.service(HttpServlet.java:646) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) root cause
org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [info.inetsolv.models.Address.student] org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:102)
When i am calling save(Child) it is working fine
please help me.i want to save records by claaing save(parent)
|