首先
创建表(mssql) 及vo
person 表
id;(主键) int;
username varchar;
password varchar;
sex varchar;
birthday DateTime;
*******************
student表
id;(主键)
grade varchar;
*******************
teacher表
id;(主键)
schoolage varchar;
/////////////////////******////////////////////////////////
再创建VO
Person
package wsq.po;
import java.util.Date;
public class Person implements java.io.Serializable {
private static final long serialVersionUID = -4431851578811178858L;
private Integer id;
private String username;
private String password;
private String sex;
private Date birthday;
public Person() {
}
public Person(String username, String password, String sex, Date birthday) {
this.username = username;
this.password = password;
this.sex = sex;
this.birthday = birthday;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSex() {
return this.sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Date getBirthday() {
return this.birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
Student
注意id属性没有了
package wsq.po;
public class Student extends Person implements java.io.Serializable {
private static final long serialVersionUID = -2981420482383402755L;
private String grade;
public Student() {
}
public String getGrade() {
return this.grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
}
Teacher
package wsq.po;
public class Teacher extends Person implements java.io.Serializable {
private static final long serialVersionUID = -8404469876025711535L;
private String schoolage;
public Teacher() {
}
public String getSchoolage() {
return this.schoolage;
}
public void setSchoolage(String schoolage) {
this.schoolage = schoolage;
}
}
////////////////////****************/////////////////////////
最关键的就是配置了
<?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">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="wsq.po.Person" table="person" schema="dbo" catalog="J2EE">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="increment" />
</id>
<property name="username" type="java.lang.String">
<column name="username" length="20" not-null="true" />
</property>
<property name="password" type="java.lang.String">
<column name="password" length="20" not-null="true" />
</property>
<property name="sex" type="java.lang.String">
<column name="sex" length="2" not-null="true" />
</property>
<property name="birthday" type="java.util.Date">
<column name="birthday" length="8" not-null="true" />
</property>
<joined-subclass name="wsq.po.Student" table="student">
<key column="id"/>
<property name="grade" type="java.lang.String" column="grade" />
</joined-subclass>
<joined-subclass name="wsq.po.Teacher" table="teacher">
<key column="id"/>
<property name="schoolage" type="java.lang.String" column="schoolage" />
</joined-subclass>
</class>
</hibernate-mapping>
posted on 2007-09-02 09:30
Crying 阅读(383)
评论(0) 编辑 收藏 所属分类:
hibernate