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

hql 一对一多表查询问题
三个实体:

  项目instance, 
  单位(申报项目的主体)Instancecorp,
  个人(申报项目的主体)Instanceperson

  项目instance, 
XML code
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.copote.nontaxteam.hibernate.pojo.Instance" table="INSTANCE" schema="XXZWZX">
        <id name="instanceid" type="java.lang.String">
            <column name="INSTANCEID" length="20" />
            <generator class="assigned" />
        </id>
        <property name="prjid" type="java.lang.String">
            <column name="PRJID" length="20" not-null="true" />
        </property>
        <property name="name" type="java.lang.String">
            <column name="NAME" length="500" />
        </property>
        <property name="declaretype" type="java.lang.String">
            <column name="DECLARETYPE" length="4" >
                <comment>申报人类型(单位/个个)</comment>
            </column>
        </property>
        <property name="acceptno" type="java.lang.String">
            <column name="ACCEPTNO" length="50" >
                <comment>受理编号</comment>
            </column>
        </property>
        <!-- 共享主键方式的一对一关联关系(与个人) -->
        <one-to-one name="instanceperson" 
            class="com.copote.nontaxteam.hibernate.pojo.Instanceperson"
            cascade="all"
            lazy="false"/>
        
        <!-- 共享主键方式的一对一关联关系 (与单位)-->
        <one-to-one name="instancecorp" 
            class="com.copote.nontaxteam.hibernate.pojo.Instancecorp"
            cascade="all"
            lazy="false"/>
       
    </class>
</hibernate-mapping>



  单位(申报项目的主体)Instancecorp,
XML code
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 单位 -->
<hibernate-mapping>
    <class name="com.copote.nontaxteam.hibernate.pojo.Instancecorp" table="INSTANCECORP" schema="XXZWZX">
        <id name="instanceid" type="java.lang.String">
            <column name="INSTANCEID" length="20" />
            <generator class="foreign">
                <param name="property">instance</param>
            </generator>
        </id>
        <!-- 共享主键方式的一对一关联关系 -->
        <one-to-one name="instance" 
            class="com.copote.nontaxteam.hibernate.pojo.Instance"
            constrained="true"/>
        <property name="corpname" type="java.lang.String">
            <column name="CORPNAME" length="100" not-null="true" />
        </property>
        <property name="corporatorcertno" type="java.lang.String">
            <column name="CORPORATORCERTNO"