两张表 
TblQx.hbm(区县表) 区县表对应多个街道
TblJd.hbm(街道表) 街道表对应一个区县
问题:获得区县表时无法得到关联的街道表信息,对象为Null,获得街道表也是一样,区县对象为Null
另外控制台只输出了一条SQL语句
望各位朋友们解决一下..以下为相关代码
      private int jdid;
     private TblQx tblQx;
     private String jd;
     private Set tblFwxxes = new HashSet(0); //些集合不包含在内
     ...省略Get/Set     private int qxid;
     private String qx;
     private Set tblJds = new HashSet(0);
     ...省略Get/Set<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2009-3-28 22:22:20 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="entity.TblQx" table="TBL_QX" schema="dbo" catalog="zf">
        <id name="qxid" type="int">
            <column name="qxid" />
            <generator class="assigned" />
        </id>
        <property name="qx" type="string">
            <column name="qx" length="50" />
        </property>
        <set name="tblJds" inverse="true" >
            <key>
                <column name="qxid" not-null="true" />
            </key>
            <one-to-many class="entity.TblJd" />
        </set>
    </class>
</hibernate-mapping><?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2009-3-28 22:22:20 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="entity.TblJd" table="TBL_JD" schema="dbo" catalog="zf">
        <id name="jdid" type="int">
            <column name="jdid" />
            <generator class="assigned" />
        </id>
        <many-to-one name="tblQx" class="entity.TblQx" fetch="select">
            <column name="qxid" not-null="true" />
        </many-to-one>
        <property name="jd" type="string">
            <column name="jd" length="50" />
        </property>
        <set name="tblFwxxes" inverse="true" >
            <key>
                <column name="jdid" />
            </key>
            <one-to-many class="entity.TblFwxx" />
        </set>
    </class>
</hibernate-mapping>

解决方案 »

  1.   

    二个问题,
    1.是一对多的关系,你设置成了多对多;
    2.你的问题就是两边都设置控制反转(inverse)了,将一的一边的inverse设为false;
      

  2.   

    建议你用工具去生成*.hbm.xml文件,比如myeclipse。
      

  3.   


            <set name="tblJds" inverse="true" > 
                <key> 
                    <column name="qxid" not-null="true" /> 
                </key> 
                <one-to-many class="entity.TblJd" /> 
            </set>       <many-to-one name="tblQx" class="entity.TblQx" fetch="select"> 
                <column name="qxid" not-null="true" /> 
            </many-to-one>  这两处对方配置的貌似都是对的
      

  4.   

    *.hbm.xml文件全部是用NetBeans IDE 6.5生成的..这个问题已经有一天了还没有搞定..郁闷中...
      

  5.   

    除了映射应该改之外,写hql的时候同样要把用到join fetch 连接上才能查到子对象
      

  6.   

    问题已解决
    只是在每个映射的后面加上了 lazy="false" 2处映射都加上了此属性 .. lazy = "检索功能"<set name="tblJds" inverse="true" lazy="false"> 
                <key> 
                    <column name="qxid" not-null="true" /> 
                </key> 
                <one-to-many class="entity.TblJd" /> 
    </set> <many-to-one name="tblQx" class="entity.TblQx" fetch="select" lazy="false"> 
                <column name="qxid" not-null="true" /> 
    </many-to-one>