one to many jpa relationship
Posted
by user309944
on Stack Overflow
See other posts from Stack Overflow
or by user309944
Published on 2010-05-22T09:35:49Z
Indexed on
2010/05/22
9:40 UTC
Read the original article
Hit count: 268
entity-relationship
Hai
I have created two table
first table as student
package com.crimson.rship;
import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.OneToMany; @Entity(name="student")
public class student {
@Id
private String stumailid;
@Basic
private String fathername;
@Basic
private String mothername;
@Basic
private String doa;
@Basic
private String dob;
public student(String stumailid,String fathername,String mothername,String doa,String dob)
{ // TODO Auto-generated constructor stub this.stumailid=stumailid; this.fathername=fathername; this.mothername=mothername; this.doa=doa; this.dob=dob; }
public void setStumailid(String stumailid) { this.stumailid = stumailid; }
public String getStumailid() { return stumailid; }
public void setFathername(String fathername) { this.fathername = fathername; }
public String getFathername() { return fathername; }
public void setMothername(String mothername) { this.mothername = mothername; }
public String getMothername() { return mothername; }
public void setDoa(String doa) { this.doa = doa; }
public String getDoa() { return doa; }
public void setDob(String dob) { this.dob = dob; }
public String getDob() { return dob; } }
Second table as mark
package com.crimson.rship;
import java.util.Collection;
import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.OneToMany; @Entity(name="mark")
public class mark {
@Id
private String stumailid;
@Basic
private String fathername;
@Basic
private String mothername;
@OneToMany(mappedBy="mark",targetEntity=student.class,fetch=FetchType.EAGER)
private Collection orders;
public mark(String stumailid,String fathername,String mothername)
{ // TODO Auto-generated constructor stub this.stumailid=stumailid; this.fathername=fathername; this.mothername=mothername;
}
public void setStumailid(String stumailid) { this.stumailid = stumailid; }
public String getStumailid() { return stumailid; }
public void setFathername(String fathername) { this.fathername = fathername; }
public String getFathername() { return fathername; }
public void setMothername(String mothername) { this.mothername = mothername; }
public String getMothername() { return mothername; }
public void setOrders(Collection orders) { this.orders = orders; }
public Collection getOrders() { return orders; } }
But this above coding working is not working correctly.can any one help me
Thanks in advance
© Stack Overflow or respective owner