Hi all,
here in my case, an EupNode class owns a set of EupNodeProvRelation, which was a subclass of NodeProvinceRelation. there are two sublasses of NodeProvinceRelation, another is IsmpNodeProvRelation, they share one table using a discrimator . The problem I met was, when I get a EupNode, by associated reference to the set of nodeProvRelation, I will get all the NodeProvinceRelation including EupNodeProviRelation and IsmpNodeProvRelation. That's not my expectation. please help, many thanks.
Hibernate version:
3.0
Mapping documents:
two classes mapping related: EupNode.hbm.xml and NodeProvinceRelation.hbm.xml
EupNode.hbm.xml
Code:
<hibernate-mapping package="entity.node">
<union-subclass name="EupNode" table="T_EUP_NODE" extends="Node"
lazy="false">
<property name="ipAddress" column="IP_ADDRESS" type="string"
length="30" not-null="false" />
<property name="ftpPort" column="FTP_PORT" type="string"
length="30" not-null="false" />
<property name="userName" column="USERNAME" type="string"
not-null="false" />
<property name="password" column="PASSWORD" type="string"
not-null="false" />
<property name="eupSyncPath" column="EUP_SYNC_PATH"
type="string" not-null="false" />
<property name="tcSyncPath" column="TC_SYNC_PATH" type="string"
not-null="false" />
<set name="provRelation" lazy="false" inverse="true"
cascade="all-delete-orphan" table="T_NODE_TO_PROVINCE" >
<key>
<column name="NODE_ID" />
</key>
<one-to-many
class="entity.node.EupNodeProvRelation" />
</set>
</union-subclass>
</hibernate-mapping>
NodeProvinceRelation.hbm.xml
Code:
<hibernate-mapping package="entity.node">
<class name="NodeProvinceRelation" table="T_NODE_TO_PROVINCE" lazy="false"
discriminator-value="0">
<id name="id" column="NODE_RELATION_ID" type="string"
length="10">
<generator class="sequence">
<param name="sequence">SEQ_NODE_RELATION_ID</param>
</generator>
</id>
<discriminator column="NODE_TYPE" type="int" />
<many-to-one name="province" column="PROVINCE_ID"
class="entity.Province"
update="true" insert="true" not-null="true"/>
<property name="nodeId" column="NODE_ID" type="string"
length="30" />
<subclass name="entity.node.EupNodeProvRelation"
discriminator-value="13">
</subclass>
<subclass name="entity.node.IsmpNodeProvRelation"
discriminator-value="99">
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Name and version of the database you are using:Oracle 9iThe creating sql of T_NODE_TO_PROVINCE is :Code:
CREATE TABLE "JUSTIN"."T_NODE_TO_PROVINCE"
( "NODE_RELATION_ID" NUMBER(10,0) NOT NULL ENABLE,
"PROVINCE_ID" VARCHAR2(2) NOT NULL ENABLE,
"NODE_ID" VARCHAR2(30) NOT NULL ENABLE,
"NODE_TYPE" NUMBER(2,0) NOT NULL ENABLE,
CONSTRAINT "PK_T_NODE_TO_PROVINCE" PRIMARY KEY ("NODE_RELATION_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "CBD_DATA" ENABLE,
CONSTRAINT "FK_T_NODE_T_REFERENCE_T_DEF_PR" FOREIGN KEY ("PROVINCE_ID")
REFERENCES "JUSTIN"."T_DEF_PROVINCE" ("PROVINCE_ID") ENABLE
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "CBD_DATA" ;
Code: