码迷,mamicode.com
首页 > Web开发 > 详细

Hibernate配置对象关联关系

时间:2015-03-15 22:51:42      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

//实体类

public class Tbs implements java.io.Serializable {

// Fields

private Integer id;
private Zbs zbs;
private String tbqy;
private String content;
private Date dates;
private Double price;
private String state;

// Constructors

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

/** minimal constructor */
public Tbs(Integer id) {
this.id = id;
}

/** full constructor */
public Tbs(Integer id, Zbs zbs, String tbqy, String content, Date dates,
Double price, String state) {
this.id = id;
this.zbs = zbs;
this.tbqy = tbqy;
this.content = content;
this.dates = dates;
this.price = price;
this.state = state;
}

// Property accessors

public Integer getId() {
return this.id;
}

public void setId(Integer id) {
this.id = id;
}

public Zbs getZbs() {
return this.zbs;
}

public void setZbs(Zbs zbs) {
this.zbs = zbs;
}

public String getTbqy() {
return this.tbqy;
}

public void setTbqy(String tbqy) {
this.tbqy = tbqy;
}

public String getContent() {
return this.content;
}

public void setContent(String content) {
this.content = content;
}

public Date getDates() {
return this.dates;
}

public void setDates(Date dates) {
this.dates = dates;
}

public Double getPrice() {
return this.price;
}

public void setPrice(Double price) {
this.price = price;
}

public String getState() {
return this.state;
}

public void setState(String state) {
this.state = state;
}

}

 

public class Zbs implements java.io.Serializable {

// Fields

private Long id;
private String name;
private String contents;
private Date enddate;
private String state;
private Set tbses = new HashSet();

// Constructors

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

/** minimal constructor */
public Zbs(Long id, String name) {
this.id = id;
this.name = name;
}

/** full constructor */
public Zbs(Long id, String name, String contents, Date enddate,
String state, Set tbses) {
this.id = id;
this.name = name;
this.contents = contents;
this.enddate = enddate;
this.state = state;
this.tbses = tbses;
}

// 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 String getContents() {
return this.contents;
}

public void setContents(String contents) {
this.contents = contents;
}

public Date getEnddate() {
return this.enddate;
}

public void setEnddate(Date enddate) {
this.enddate = enddate;
}

public String getState() {
return this.state;
}

public void setState(String state) {
this.state = state;
}

public Set getTbses() {
return this.tbses;
}

public void setTbses(Set tbses) {
this.tbses = tbses;
}

}

public class Demo {

/** 测试类
* @param args
*/
public static void main(String[] args) {
Session session=HibernateSessionFactory.getSession();
/* Tbs tbs=(Tbs) session.get(Tbs.class, 1);
System.out.println("项目名称"+"投标企业"+"报价");
System.out.println(tbs.getZbs().getName());
System.out.println(tbs.getZbs().getName()+tbs.getTbqy()+tbs.getPrice());*/
Zbs zbs=(Zbs) session.get(Zbs.class, (long)4);
Set<Tbs> tbs=zbs.getTbses();
String string="";
for (Tbs tbs2 : tbs) {

string+=tbs2.getTbqy()+",";

}
System.out.println("编号"+"项目名称"+"企业名称");
System.out.println(zbs.getId()+zbs.getName()+string);

}

}

Hibernate配置对象关联关系

标签:

原文地址:http://www.cnblogs.com/mengzhen123/p/4340451.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!