日期:2014-05-18 浏览次数:20716 次
@Entity
@Table(name="teacherstable")
public class Teacher {
private int m_ID;
private int m_AGE;
private String m_NAME;
@Id
@Column(name="ID")
public int getM_ID() {
return m_ID;
}
public void setM_ID(int m_ID) {
this.m_ID = m_ID;
}
@Column(name="Age")
public int getM_AGE() {
return m_AGE;
}
public void setM_AGE(int m_AGE) {
this.m_AGE = m_AGE;
}
@Column(name="Name")
public String getM_NAME() {
return m_NAME;
}
public void setM_NAME(String m_NAME) {
this.m_NAME = m_NAME;
}
}
//////////////////我是华丽的昏割线//////////////////////////
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s = new Student();
s.setID(87);
s.setAge(43);
s.setName("sd");
Teacher t = new Teacher();
t.setM_ID(87);
t.setM_AGE(43);
t.setM_NAME("sd");
AnnotationConfiguration cfg = new AnnotationConfiguration();
SessionFactory sf = cfg.configure().buildSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
session.save(t);
session.getTransaction().commit();
session.close();
sf.close();