Chinaunix首页 | 论坛 | 博客
  • 博客访问: 102559
  • 博文数量: 60
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 280
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-09 12:19
文章分类

全部博文(60)

文章存档

2015年(3)

2014年(41)

2013年(16)

我的朋友

分类: Web开发

2014-04-19 23:53:46


配置映射:
1.courseinfo类:

package com.xiyou.dao.po;


import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name="classes")
public class ClassesInfo implements Serializable{
private String class_no;
private String class_name;
private String class_des;
private Profession pro;
private Set stu = new HashSet();
@Id
@Column(name="classno")
public String getClass_no() {
return class_no;
}
public void setClass_no(String class_no) {
this.class_no = class_no;
}
@Column(name="classname")
public String getClass_name() {
return class_name;
}
public void setClass_name(String class_name) {
this.class_name = class_name;
}
@Column(name="classdescribe")
public String getClass_des() {
return class_des;
}
public void setClass_des(String class_des) {
this.class_des = class_des;
}
@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name="prono")
public Profession getPro() {
return pro;
}
public void setPro(Profession pro) {
this.pro = pro;
}
@OneToMany(mappedBy="cla")
public Set getStu() {
return stu;
}
public void setStu(Set stu) {
this.stu = stu;
}


}


2.Teacher类
package com.xiyou.dao.po;


import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name="teacher")
public class Teacher implements Serializable {
private String tea_no;
private String tea_name;
private int tea_sex;
private String tea_title;
private String tea_id;
private String tea_des;
private int age;
private DepartMent deptea;
private Set teacou = new HashSet();


public Teacher() {
super();
}
public Teacher(String tea_no, String tea_name, int tea_sex,
String tea_title, String tea_id, String tea_des, int age,
DepartMent deptea, Set teacou) {
super();
this.tea_no = tea_no;
this.tea_name = tea_name;
this.tea_sex = tea_sex;
this.tea_title = tea_title;
this.tea_id = tea_id;
this.tea_des = tea_des;
this.age = age;
this.deptea = deptea;
this.teacou = teacou;
}
@Id
@Column(name="tno")
public String getTea_no() {
return tea_no;
}
public void setTea_no(String tea_no) {
this.tea_no = tea_no;
}
@Column(name="tname")
public String getTea_name() {
return tea_name;
}
public void setTea_name(String tea_name) {
this.tea_name = tea_name;
}
@Column(name="sex")
public int getTea_sex() {
return tea_sex;
}
public void setTea_sex(int tea_sex) {
this.tea_sex = tea_sex;
}
@Column(name="title")
public String getTea_title() {
return tea_title;
}
public void setTea_title(String tea_title) {
this.tea_title = tea_title;
}
@Column(name="tid")
public String getTea_id() {
return tea_id;
}
public void setTea_id(String tea_id) {
this.tea_id = tea_id;
}
@Column(name="tdescribe")
public String getTea_des() {
return tea_des;
}
public void setTea_des(String tea_des) {
this.tea_des = tea_des;
}
@Column(name="tage")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

@ManyToOne
@JoinColumn(name="deptno")
public DepartMent getDeptea() {
return deptea;
}
public void setDeptea(DepartMent deptea) {
this.deptea = deptea;
}
@OneToMany(mappedBy="tea_cou",cascade=CascadeType.ALL,fetch=FetchType.LAZY)
public Set getTeacou() {
return teacou;
}
public void setTeacou(Set teacou) {
this.teacou = teacou;
}
}

3.TeacherCourse类:
package com.xiyou.dao.po;


import java.io.Serializable;


import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;


import com.xiyou.dao.po.TeacherCourseId;


@Entity
@Table(name="teacher_course")
public class TeacherCourse implements Serializable{
private String tea_cou_weekdays;
private String tea_cou_period;
private int tea_cou_cplan;
private Teacher tea_cou;
private Courseinfo cou_cou;
private TeacherCourseId id;


public TeacherCourse() {
super();
}
public TeacherCourse(String tea_cou_weekdays, String tea_cou_period,
int tea_cou_cplan, Teacher tea_cou, Courseinfo cou_cou,
TeacherCourseId id) {
super();
this.tea_cou_weekdays = tea_cou_weekdays;
this.tea_cou_period = tea_cou_period;
this.tea_cou_cplan = tea_cou_cplan;
this.tea_cou = tea_cou;
this.cou_cou = cou_cou;
this.id = id;
}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "tno", column = @Column(name = "tno", nullable = false, length = 20)),
@AttributeOverride(name = "cno", column = @Column(name = "cno", nullable = false, length = 20)) })
public TeacherCourseId getId() {
return id;
}
public void setId(TeacherCourseId id) {
this.id = id;
}
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "cno", nullable = false, insertable = false, updatable = false)
public Teacher getTea_cou() {
return tea_cou;
}
public void setTea_cou(Teacher tea_cou) {
this.tea_cou = tea_cou;
}
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "tno", nullable = false, insertable = false, updatable = false)
public Courseinfo getCou_cou() {
return cou_cou;
}
public void setCou_cou(Courseinfo cou_cou) {
this.cou_cou = cou_cou;
}
@Column(name="weekday")
public String getTea_cou_weekdays() {
return tea_cou_weekdays;
}
public void setTea_cou_weekdays(String tea_cou_weekdays) {
this.tea_cou_weekdays = tea_cou_weekdays;
}
@Column(name="period")
public String getTea_cou_period() {
return tea_cou_period;
}
public void setTea_cou_period(String tea_cou_period) {
this.tea_cou_period = tea_cou_period;
}
@Column(name="cplan")
public int getTea_cou_cplan() {
return tea_cou_cplan;
}
public void setTea_cou_cplan(int tea_cou_cplan) {
this.tea_cou_cplan = tea_cou_cplan;
}


}

创建一个Id类如下:
package com.xiyou.dao.po;

import javax.persistence.Column;
import javax.persistence.Embeddable;


/**
 * TeacherCourseId entity. @author MyEclipse Persistence Tools
 */
@Embeddable
public class TeacherCourseId extends TeacherCourse implements
java.io.Serializable {


// Fields


private String tno;
private String cno;


// Constructors


/** default constructor */
public TeacherCourseId() {
}


/** full constructor */
public TeacherCourseId(String tno, String cno) {
this.tno = tno;
this.cno = cno;
}


// Property accessors


@Column(name = "tno", nullable = false, length = 20)
public String getTno() {
return this.tno;
}


public void setTno(String tno) {
this.tno = tno;
}


@Column(name = "cno", nullable = false, length = 20)
public String getCno() {
return this.cno;
}


public void setCno(String cno) {
this.cno = cno;
}


public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof TeacherCourseId))
return false;
TeacherCourseId castOther = (TeacherCourseId) other;


return ((this.getTno() == castOther.getTno()) || (this.getTno() != null
&& castOther.getTno() != null && this.getTno().equals(
castOther.getTno())))
&& ((this.getCno() == castOther.getCno()) || (this.getCno() != null
&& castOther.getCno() != null && this.getCno().equals(
castOther.getCno())));
}


public int hashCode() {
int result = 17;


result = 37 * result
+ (getTno() == null ? 0 : this.getTno().hashCode());
result = 37 * result
+ (getCno() == null ? 0 : this.getCno().hashCode());
return result;
}


}
这个
问题让我搞了一周终于解决了!
最后一个Id类如果实在不会写的话,可以通过反向工程做:


阅读(938) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~