| Hi:
 I have following tables:
 
 Table:UserData:
 id
 name
 
 Table:Parent_child
 parentId
 childId
 ( i dont want to add third column here, as pk, but use these two as compositekey)
 
 
 UserData.java
 
 @Id
 @Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 40)
 public String getId() {
 return this.id;
 }
 public void setId(String id) {
 this.id = id;
 }
 @Column(name = "NAME", unique = true, nullable = false, insertable = true, updatable = true, length = 40)
 public String getName() {
 return this.id;
 }
 public void setName(String id) {
 this.id = id;
 }
 @OneToMany(fetch = FetchType.LAZY,mappedBy="parentProfile")
 public Set<ParentChildr> getParents() {
 return parents;
 }
 
 public void setParents(Set<ParentChild> parents) {
 this.parents = parents;
 }
 
 @OneToMany(fetch = FetchType.LAZY,mappedBy="studentProfile")
 public Set<ParentChild> getStudents() {
 return students;
 }
 
 public void setStudents(Set<ParentChild> students) {
 this.students = students;
 }
 
 ParentChild.java
 
 @Embeddable
 public static class Id implements Serializable{
 private String parentProfileId;
 private String studentProfileId;
 
 
 
 public Id(){}
 
 
 public Id(String parentProfileId, String studentProfileId) {
 this.parentProfileId = parentProfileId;
 this.studentProfileId = studentProfileId;
 }
 
 @Column(name = "PARENT_ID", nullable = false)
 public String getParentProfileId() {
 return parentProfileId;
 }
 public void setParentProfileId(String parentProfileId) {
 this.parentProfileId = parentProfileId;
 }
 
 @Column(name = "STUDENT_ID", nullable = false)
 public String getStudentProfileId() {
 return studentProfileId;
 }
 public void setStudentProfileId(String studentProfileId) {
 this.studentProfileId = studentProfileId;
 }
 
 
 }
 
 
 private Id id = new Id();
 
 @EmbeddedId
 public Id getId() {
 return id;
 }
 
 public void setId(Id id) {
 this.id = id;
 }
 
 private User parentProfile;
 private User studentProfile;
 
 public ParentChild(User parentPorilfe, User studentPorilfe){
 this.parentProfile = parentPorilfe;
 this.studentProfile = studentPorilfe;
 }
 
 @ManyToOne(fetch = FetchType.LAZY)
 @JoinColumn(name="PARENT_ID",insertable=false,updatable=false)
 public User getParentProfile() {
 return parentProfile;
 }
 public void setParentProfile(User parentProfile) {
 this.parentProfile = parentProfile;
 }
 
 @ManyToOne(fetch = FetchType.LAZY)
 @JoinColumn(name="STUDENT_ID",insertable=false,updatable=false)
 public User getStudentProfile() {
 return studentProfile;
 }
 public void setStudentProfile(User studentProfile) {
 this.studentProfile = studentProfile;
 }
 
 
 I'm trying to add as:
 
 ParentChild parentChild = new ParentChild(parent,child);
 em.persist(parentChild);
 
 
 I'm getting error:
 
 cannot insert NULL into ("USERSCHEMA"."PARENT_CHILD"."PARENT_ID")
 Both parent and child object in above code are not null and pulled from DB.
 
 pls help...
 
 
 |