Hibernate one Many Example
hibernate one-to-many
=============================================================
=============================================================
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Anish
-->
<hibernate-mapping>
<class name="session.Student" table="STUDENT" schema="RUBY">
<id name="id" type="java.lang.Long">
<column name="ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" length="10" />
</property>
<set name="subjects" inverse="true">
<key>
<column name="EMPID" precision="22" scale="0" />
</key>
<one-to-many class="session.Subject" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
ANish
-->
<hibernate-mapping>
<class name="session.Subject" table="SUBJECT" schema="RUBY">
<id name="id" type="java.lang.Long">
<column name="ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<many-to-one cascade="save-update" name="student" class="session.Student" fetch="select">
<column name="EMPID" precision="22" scale="0" />
</many-to-one>
<property name="name" type="java.lang.String">
<column name="NAME" length="10" />
</property>
</class>
</hibernate-mapping>
related
Relation One to Many Hibernate Java
hibernate one-to-many
hibernate one-to-many list
hibernate one-to-many set
hibernate one-to-many example
hibernate one-to-many cascade
hibernate one-to-many annotation
hibernate one-to-one
hibernate many-to-many
hibernate many to one cascade
ANish
public class Student implements java.io.Serializable {
// Fields
private Long id;
private String name;
private Set subjects = new HashSet(0);
// Constructors
/** default constructor */
public Student() {
}
/** minimal constructor */
public Student(Long id) {
this.id = id;
}
/** full constructor */
public Student(Long id, String name, Set subjects) {
this.id = id;
this.name = name;
this.subjects = subjects;
}
// Property accessors
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Set getSubjects() {
return this.subjects;
}
public void setSubjects(Set subjects) {
this.subjects = subjects;
}
}
public class Subject implements java.io.Serializable {
// Fields
private Long id;
private Student student;
private String name;
// Constructors
/** default constructor */
public Subject() {
}
/** minimal constructor */
public Subject(Long id) {
this.id = id;
}
/** full constructor */
public Subject(Long id, Student student, String name) {
this.id = id;
this.student = student;
this.name = name;
}
// Property accessors
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Student getStudent() {
return this.student;
}
public void setStudent(Student student) {
this.student = student;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
No comments:
Post a Comment