[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3342) one to many association with a subclass of a class having discriminator column creates wrong sql
Abhijit (JIRA)
noreply at atlassian.com
Wed Jun 11 11:29:33 EDT 2008
one to many association with a subclass of a class having discriminator column creates wrong sql
------------------------------------------------------------------------------------------------
Key: HHH-3342
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3342
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.2.6, 3.1.3, 3.0.5
Environment: Tested on Hibernate Version 3.0.5, 3.1.1 & 3.2.6.ga. CGLIB-2.1.3
Reporter: Abhijit
I have one abstract class which has two sub classes and each each sub class has further subclasses. The second level subclasses doesn't have tables and only has discriminator value. As below:
<hibernate-mapping
>
<class
name="edu.wustl.catissuecore.domain.AbstractSpecimen"
table="CATISSUE_ABSTRACT_SPECIMEN"
lazy="true"
>
<id
name="id"
column="IDENTIFIER"
type="long"
length="30"
unsaved-value="null"
>
<generator class="native">
<param name="sequence">CATISSUE_ABSTRACT_SPECIMEN_SEQ</param>
</generator>
</id>
<discriminator column="SPECIMEN_CLASS" type="string"/>
<subclass name="edu.wustl.catissuecore.domain.Specimen" discriminator-value="Specimen">
<join table="CATISSUE_SPECIMEN">
<key column="IDENTIFIER"/>
<property
name="positionDimensionOne"
type="int"
update="true"
/>
......
</join>
<subclass
name="edu.wustl.catissuecore.domain.FluidSpecimen"
discriminator-value="Fluid" lazy="true"
>
</subclass>
<subclass name="edu.wustl.catissuecore.domain.CellSpecimen"
discriminator-value="Cell" lazy="true"
>
</subclass>
</subclass>
<subclass name="edu.wustl.catissuecore.domain.RequirementSpecimen" discriminator-value="ReqSpecimen">
<join table="CATISSUE_CP_REQ_SPECIMEN">
<key column="IDENTIFIER"/>
<property
name="storageType"
type="int"
update="true"
/>
......
</join>
<subclass
name="edu.wustl.catissuecore.domain.FluidSpecimen"
discriminator-value="Fluid" lazy="true"
>
</subclass>
<subclass name="edu.wustl.catissuecore.domain.CellSpecimen"
discriminator-value="Cell" lazy="true"
>
</subclass>
</subclass>
</class>
</hibernate-mapping>
--------------------------------------
<hibernate-mapping
>
<class
name="edu.wustl.catissuecore.domain.AbstractSpecimenCollectionGroup"
table="CATISSUE_ABS_SPECI_COLL_GROUP"
lazy="true"
>
<id
name="id"
column="IDENTIFIER"
type="long"
length="30"
unsaved-value="null"
>
<generator class="native">
<param name="sequence">CATISSUE_SPECIMEN_COLL_GRP_SEQ</param>
</generator>
</id>
<property
name="name"
type="string"
update="true"
insert="true"
column="NAME"
length="255"
/>
<property
name="clinicalDiagnosis"
type="string"
update="true"
insert="true"
column="CLINICAL_DIAGNOSIS"
length="150"
/>
.....
.......
<joined-subclass
name="edu.wustl.catissuecore.domain.CollectionProtocolEvent"
table="CATISSUE_COLL_PROT_EVENT" lazy="false"
>
<key
column="IDENTIFIER"
/>
<property
name="collectionPointLabel"
type="string"
update="true"
insert="true"
column="COLLECTION_POINT_LABEL"
length="255"
/>
<set
name="requirementSpecimenCollection"
table="CATISSUE_CP_REQ_SPECIMEN"
lazy="true"
inverse="true"
cascade="save-update"
fetch="subselect"
sort="unsorted"
>
<key
column="COLLECTION_PROTOCOL_EVENT_ID"
/>
<one-to-many
class="edu.wustl.catissuecore.domain.RequirementSpecimen"
/>
</set>
.....
</joined-subclass>
</class>
</hibernate-mapping>
--------------------------------------
In above configuration 'CollectionProtocolEvent' which is a joined -subclass of 'AbstractSpecimenCollectionGroup' has one to many association with RequirementSpecimen which is subclass of AbstractSpecimen.
It was found that whenever we execute following code:
line 1: CollectionProtocolEvent cpe =(CollectionProtocolEvent) session.get(CollectionProtocolEvent.class,new Long(101));
line2: cpe.getRequirementSpecimenCollection ();
At line 2 hibernate generates wrong query. In select column it generates
'AbstractSpecimen.COLLECTION_PROTOCOL_EVENT_ID,...from' but it should be 'RequirementSpecimen .COLLECTION_PROTOCOL_EVENT_ID,...from..'
Hence it gives error "unknown column" It has been observed that inner join part of the query gets generated properly. But in select part it always takes parent table's alias.
In case we use joined-class instead of subclass without driminator everything works fine.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list