hibernate exm with annotation
package com.jtc.p1;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Table;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
@Entity
@Table(name="stud")
public class Student_Pojo {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="sid")
private int sid;
@Column(name="sname")
private String sname;
@Column(name="dob")
private String dob;
@Column(name="qualification")
private String qualification;
@CollectionOfElements
@JoinTable(name="course")
@JoinColumn(name="sid")
@IndexColumn(name="xid")
@Column(name="cname")
private String[] courses;
@CollectionOfElements
@JoinTable(name="emails")
@JoinColumn(name="sid")
@IndexColumn(name="xid")
@Column(name="emailid")
private List<String> email;
@CollectionOfElements
@JoinTable(name="markes")
@JoinColumn(name="sid")
@IndexColumn(name="xid")
@Column(name="studentMarks")
private List<Integer> marks;
@CollectionOfElements
@JoinTable(name="phones")
@JoinColumn(name="sid")
@Column(name="phoneNo")
private Set<Long> phone;
@CollectionOfElements
@JoinTable(name="refss")
@JoinColumn(name="sid")
@Column(name="ReffName")
@org.hibernate.annotations.MapKey(columns=@Column(name="ReffNo"))
private Map<String,Long> refs;
public Student_Pojo() {
//default constructor....
}
// generate constructor using field;
public Student_Pojo( String sname, String dob, String qualification, String[] courses, List<String> email,
List<Integer> marks, Set<Long> phone, Map<String, Long> refs) {
this.sname = sname;
this.dob = dob;
this.qualification = qualification;
this.courses = courses;
this.email = email;
this.marks = marks;
this.phone = phone;
this.refs = refs;
}
//setter and getter
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getQualification() {
return qualification;
}
public void setQualification(String qualification) {
this.qualification = qualification;
}
public String[] getCourses() {
return courses;
}
public void setCourses(String[] courses) {
this.courses = courses;
}
public List<String> getEmail() {
return email;
}
public void setEmail(List<String> email) {
this.email = email;
}
public List<Integer> getMarks() {
return marks;
}
public void setMarks(List<Integer> marks) {
this.marks = marks;
}
public Set<Long> getPhone() {
return phone;
}
public void setPhone(Set<Long> phone) {
this.phone = phone;
}
public Map<String, Long> getRefs() {
return refs;
}
public void setRefs(Map<String, Long> refs) {
this.refs = refs;
}
}
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Table;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.IndexColumn;
@Entity
@Table(name="stud")
public class Student_Pojo {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="sid")
private int sid;
@Column(name="sname")
private String sname;
@Column(name="dob")
private String dob;
@Column(name="qualification")
private String qualification;
@CollectionOfElements
@JoinTable(name="course")
@JoinColumn(name="sid")
@IndexColumn(name="xid")
@Column(name="cname")
private String[] courses;
@CollectionOfElements
@JoinTable(name="emails")
@JoinColumn(name="sid")
@IndexColumn(name="xid")
@Column(name="emailid")
private List<String> email;
@CollectionOfElements
@JoinTable(name="markes")
@JoinColumn(name="sid")
@IndexColumn(name="xid")
@Column(name="studentMarks")
private List<Integer> marks;
@CollectionOfElements
@JoinTable(name="phones")
@JoinColumn(name="sid")
@Column(name="phoneNo")
private Set<Long> phone;
@CollectionOfElements
@JoinTable(name="refss")
@JoinColumn(name="sid")
@Column(name="ReffName")
@org.hibernate.annotations.MapKey(columns=@Column(name="ReffNo"))
private Map<String,Long> refs;
public Student_Pojo() {
//default constructor....
}
// generate constructor using field;
public Student_Pojo( String sname, String dob, String qualification, String[] courses, List<String> email,
List<Integer> marks, Set<Long> phone, Map<String, Long> refs) {
this.sname = sname;
this.dob = dob;
this.qualification = qualification;
this.courses = courses;
this.email = email;
this.marks = marks;
this.phone = phone;
this.refs = refs;
}
//setter and getter
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getQualification() {
return qualification;
}
public void setQualification(String qualification) {
this.qualification = qualification;
}
public String[] getCourses() {
return courses;
}
public void setCourses(String[] courses) {
this.courses = courses;
}
public List<String> getEmail() {
return email;
}
public void setEmail(List<String> email) {
this.email = email;
}
public List<Integer> getMarks() {
return marks;
}
public void setMarks(List<Integer> marks) {
this.marks = marks;
}
public Set<Long> getPhone() {
return phone;
}
public void setPhone(Set<Long> phone) {
this.phone = phone;
}
public Map<String, Long> getRefs() {
return refs;
}
public void setRefs(Map<String, Long> refs) {
this.refs = refs;
}
}
Comments
Post a Comment