当前位置: 代码迷 >> Java Web开发 >> hibernate一对多查询,小弟我要崩溃啦!
  详细解决方案

hibernate一对多查询,小弟我要崩溃啦!

热度:4   发布时间:2016-04-17 12:14:32.0
hibernate一对多查询,我要崩溃啦!!!!
数据库中分别有Cityscenery(城市表)Business(商业区表)。一个城市中可以有多个商业区。因为这个项目中不可以删除任何东西,所以我没有建立住外键关联。商业区中记录的是城市的ID但是我却要显示城市的名称。现在的问题是,如果我不建立
many-to-one,显示城市的ID可以正确显示,但是我建立many-to-one想要显示城市名称的时候查询的时候返回的List中全部都是null.代码如下: 我用的是tomcat连接池,会是因为连接池中的最大连接数太小吗?
Business.hbm.xml:
<hibernate-mapping>
  <class name="po.Business" table="business" catalog="hotel">
  <id name="businessId" type="java.lang.Integer">
  <column name="Business_Id" />
  <generator class="increment" />
  </id>
  <many-to-one name="city" class="po.Business">
  <column name="cityId"/>
  </many-to-one>
  <property name="businessName" type="java.lang.String">
  <column name="Business_name" length="50" />
  </property>
  <property name="businessEn" type="java.lang.String">
  <column name="Business_en" length="50" />
  </property>
  <property name="businessControl" type="java.lang.String">
  <column name="Business_control" length="30" />
  </property>
  <property name="businessDate" type="java.util.Date">
  <column name="Business_date" length="0" />
  </property>
  <property name="businessSign" type="java.lang.Integer">
  <column name="Business_sign" />
  </property>
  <property name="businessRemark" type="java.lang.String">
  <column name="Business_remark" length="250" />
  </property>
  </class>
</hibernate-mapping>

Business.java:
public class Business implements java.io.Serializable {

// Fields
private Integer businessId;
private Cityscenery city;
private String businessName;
private String businessEn;
private String businessControl;
private Date businessDate;
private Integer businessSign;
private String businessRemark;

// Constructors

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

public Business(Cityscenery city, String businessName, String businessEn,
String businessControl, Date businessDate, Integer businessSign,
String businessRemark) {
this.city = city;
this.businessName = businessName;
this.businessEn = businessEn;
this.businessControl = businessControl;
this.businessDate = businessDate;
this.businessSign = businessSign;
this.businessRemark = businessRemark;
}
public Integer getBusinessId() {
return this.businessId;
}
public void setBusinessId(Integer businessId) {
this.businessId = businessId;
}
public Cityscenery getCity() {
return city;
}
public void setCity(Cityscenery city) {
this.city = city;
}
public String getBusinessName() {
return this.businessName;
}
public void setBusinessName(String businessName) {
this.businessName = businessName;
}
public String getBusinessEn() {
return this.businessEn;
}
public void setBusinessEn(String businessEn) {
this.businessEn = businessEn;
}
public String getBusinessControl() {
return this.businessControl;
}
public void setBusinessControl(String businessControl) {
  相关解决方案