-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Issue with MAnyToMany ...
PostPosted: Thu Apr 15, 2010 9:51 pm 
Newbie

Joined: Thu Apr 15, 2010 9:05 pm
Posts: 1
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...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.