日期:2014-05-17  浏览次数:20636 次

关于hibernate关联映射查询的问题
我有个商品表和商品属性表 是一对多的关系 但是关联映射查询的时候却只能查出一个商品的属性 不明白哪里错了 纠结 就大神解答

我的配置文件
XML code

    <class name="ccsu.bango.goods.model.Goods" table="TB_GOODS">
        <id name="goodsId" type="java.lang.Integer">
            <column name="ID"></column>
        </id>
        <property name="classId">
            <column name="CLASS_ID"></column>
        </property>
        <property name="status">
            <column name="STATUS"></column>
        </property>
        <bag name="goodsPropList" inverse="true">
            <key column="ID"></key>
            <one-to-many class="ccsu.bango.goods.model.GoodsProp"/>
        </bag>
    </class>
    
    <class name="ccsu.bango.goods.model.GoodsProp" table="TB_GOODSPROPS">
        <id name="goodsPropId">
            <column name="ID"></column>
        </id>
        <property name="propNameId">
            <column name="PROP_ID"></column>
        </property>
        <property name="propValueId">
            <column name="VALUE_ID"></column>
        </property>
        <property name="goodsId">
            <column name="GOODS_ID"></column>
        </property>
    </class>


两个类
Java code

package ccsu.bango.goods.model;

public class GoodsProp {
    
    private Integer goodsPropId;
    private Integer propNameId;
    private Integer propValueId;
    private Integer goodsId;
    
    public GoodsProp() {
        // TODO Auto-generated constructor stub
    }
    
    public GoodsProp(Integer goodsPropId, Integer propNameId,
            Integer propValueId, Integer goodsId) {
        this.goodsPropId = goodsPropId;
        this.propNameId = propNameId;
        this.propValueId = propValueId;
        this.goodsId = goodsId;
    }

    public Integer getGoodsPropId() {
        return goodsPropId;
    }
    public void setGoodsPropId(Integer goodsPropId) {
        this.goodsPropId = goodsPropId;
    }
    public Integer getPropNameId() {
        return propNameId;
    }
    public void setPropNameId(Integer propNameId) {
        this.propNameId = propNameId;
    }
    public Integer getPropValueId() {
        return propValueId;
    }
    public void setPropValueId(Integer propValueId) {
        this.propValueId = propValueId;
    }
    public Integer getGoodsId() {
        return goodsId;
    }
    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }
    
}



Java code

package ccsu.bango.goods.model;

import java.util.List;

public class Goods {

    private Integer goodsId;
    private Integer classId;
    private Integer status;
    
    private List goodsPropList;

    public Goods() {
        // TODO Auto-generated constructor stub
    }
    
    public Goods(Integer goodsId, Integer classId, Integer status,
            List goodsPropList) {
        this.goodsId = goodsId;
        this.classId = classId;
        this.status = status;
        this.goodsPropList = goodsPropList;
    }

    public Integer getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }

    public Integer getClassId() {
        re