有3张表相关联,  我在关联插入数据的时候,出现问题!  例如:ground表,groundType表,product表。  
   我操作插值的时候,  ground与groundType之间在数据库中 主外键能体现出来,但是product这种表不能体现出groundType的主外键!  
    grt.getgroundSet().add(gr);我是这样关联groundType与product的 主外键的。

解决方案 »

  1.   

    <hibernate-mapping>
    <class name="com.pxcs.model.GroundType" table="t_groundType"> <id name="id" column="id" type="int">
    <generator class="native" />
    </id>
    <property name="groundTypeName" column="groundTypeName" type="string"></property>
    <set name="grounds" table="t_trainGround" inverse="true" cascade="delete">
    <key column="fk_gtid"></key>
    <one-to-many class="com.pxcs.model.TrainGround"/>
    </set>
    </class>
    </hibernate-mapping>
    这是  groundType这张表的体现
     <subclass name="com.pxcs.model.TrainGround" discriminator-value="GROUND">
            <join table="t_trainGround" fetch="select">
                <key column="PAYMENT_ID"/>
                <property name="seatNum" column="seatNum" type="string"></property>
    <property name="address" column="address" type="string"></property>
    <property name="startDate" column="startDate" type="string"></property>
    <property name="endDate" column="endDate" type="string"></property>
    <many-to-one name="groundType" class="com.pxcs.model.GroundType" column="fk_gtid" ></many-to-one>
            </join>
        </subclass>
    这是 product这张表的体现
      

  2.   

    我以前做的都不在数据库里体现关系的 把关联的表的两个字段类型设置成一样
    然后在实现业务的时候用 A.id=B.id这种。
      

  3.   

    你这个应该是多对多的映射吧,按照你的思路应该拆分成多对一,一对多,你的多对一配置的不对吧,你看下hebernate帮助文档,多对一不是你那么配置的