标签:ret log nat oid port asc ber pack builds
Card类
package cn.OneToOne2017109.entity; import javax.persistence.*; /** * Created by YSS on 2017/10/9. */
@Entity
@Table(name = "Card")
public class Card {
@Id
@GeneratedValue
private Integer cid;
@Column
private String cnum;
@OneToOne(mappedBy = "card",cascade = CascadeType.ALL)
private People people;
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getCnum() {
return cnum;
}
public void setCnum(String cnum) {
this.cnum = cnum;
}
public People getPeople() {
return people;
}
public void setPeople(People people) {
this.people = people;
}
}
People类
@Entity @Table(name = "People") public class People { @Id @GeneratedValue private Integer pid; @Column private String pname; @OneToOne @JoinColumn(name = "cid") private Card card; public Integer getPid() { return pid; } public void setPid(Integer pid) { this.pid = pid; } public String getPname() { return pname; } public void setPname(String pname) { this.pname = pname; } public Card getCard() { return card; } public void setCard(Card card) { this.card = card; } }
测试类
public class testonetoone { Configuration cfg; SessionFactory factory; Session session; Transaction tx; @Before public void mybefor(){ cfg=new Configuration().configure(); factory=cfg.buildSessionFactory(); session=factory.openSession(); tx=session.beginTransaction(); } @After public void myafter(){ tx.commit(); } @Test public void test03() { People people=new People(); Card card=new Card(); people.setPname("123"); card.setCnum("123133"); card.setPeople(people); people.setCard(card); session.save(card); } }
将大配置中的mapping节点改为
<mapping class=" "/>
标签:ret log nat oid port asc ber pack builds
原文地址:http://www.cnblogs.com/hfddz/p/7642094.html