-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: 1:M relationship to a subclass
PostPosted: Fri Jul 23, 2004 12:04 pm 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
I have a 1:M relationship, and the class on the M side is mapped as a subclass. For this particular relationship, I only want the specified class returned on the M side. Unfortunately, Hibernate does not seem to include the discriminator value in the query when it is retrieving the related objects. Any ideas?

Mappings:
the '1' side:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM
   "file:///C:/hibernate-2.1/src/net/sf/hibernate/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="ca.gc.csc_scc.omsr.model">
   <class name="Incident" table="incident">
      <id name="id" access="field" column="incident_id">
         <generator class="native">
            <param name="sequence">GENERIC_PK_SEQ</param>
         </generator>
      </id>
      <version name="version" column="version" access="field" type="integer"/>
      <property name="contraband" access="field"
         column="contr_unauth_item_seized_flag" type="yes_no"/>
      <property name="currentSituation" access="field"
         column="current_situation_comment"/>
      <many-to-one name="facility" access="field" class="Facility"
         cascade="none" outer-join="false" column="facility_code"
         not-null="true"/>
      <property name="finalizedDate" access="field"
         column="report_finalized_timestamp" type="timestamp"/>
      <property name="incidentDate" access="field"
         column="incident_timestamp" type="timestamp" not-null="true"/>
      <property name="incidentNumber" access="field" column="incident_number"
         not-null="true" unique="true"/>
      <many-to-one name="incidentQualifier" access="field"
         class="IncidentQualifier" cascade="none" outer-join="false"
         column="incident_qualifier_code"/>
      <many-to-one name="incidentSubType" access="field"
         class="IncidentSubType" cascade="none" outer-join="false"
         column="incident_type_code"/>
      <many-to-one name="incidentType" access="field" class="IncidentType"
         cascade="none" outer-join="false" column="incident_category_code"
         not-null="true"/>
      <property name="lockdownComment" access="field"
         column="lock_down_comment"/>
      <many-to-one name="lockdownType" access="field" class="LockdownType"
         cascade="none" outer-join="false" column="lock_down_type_code"/>
      <property name="offenderInjured" access="field"
         column="offender_injury_flag" type="yes_no"/>
      <set name="offendersInvolved" access="field" inverse="true"
         cascade="all-delete-orphan">
         <key column="incident_id"/>
         <one-to-many class="OffenderInvolved"/>
      </set>
      <property name="otherInjured" access="field" column="other_injury_flag"
         type="yes_no"/>
      <property name="outsideAgencyContacted" access="field"
         column="agencies_contacted_flag" type="yes_no"/>
      <property name="propertyDamage" access="field"
         column="proprety_damages_flag" type="yes_no"/>
      <property name="staffInjured" access="field" column="staff_injury_flag"
         type="yes_no"/>
      <property name="synopsis" access="field" column="incident_synopsis"/>
      <property name="useOfForce" access="field" column="use_of_force_flag"
         type="yes_no"/>
      <property name="weaponUsageByOffender" access="field"
         column="weapon_used_flag" type="yes_no"/>
   </class>
</hibernate-mapping>

the 'M' side:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping SYSTEM
   "file:///C:/hibernate-2.1/src/net/sf/hibernate/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="ca.gc.csc_scc.omsr.model">
   <class name="PersonInvolved" table="persons_involved" discriminator-value="X">
      <id name="id" access="field" column="person_id">
         <generator class="native">
            <param name="sequence">GENERIC_PK_SEQ</param>
         </generator>
      </id>
      <discriminator column="person_category_code" type="string" force="true"/>
      <version name="version" column="version" access="field" type="integer"/>
      <many-to-one name="incident" access="field" class="Incident"
         cascade="none" column="incident_id" not-null="true"/>
      <property name="injured" access="field" column="injury_flag"
         type="yes_no"/>
      <set name="roles" access="field" table="incident_role"
         cascade="all">
         <key column="person_id"/>
         <many-to-many class="IncidentRole" column="incident_role_code"/>
      </set>
      <subclass name="OffenderInvolved"
         discriminator-value="0001">
         <property name="disciplined" access="field"
            column="discipline_offender_flag" type="yes_no"/>
         <many-to-one name="offender" access="field" class="Offender"
            cascade="none" column="offender_number" not-null="true"/>
         <property name="offenderId" access="field" column="offender_number" insert="false" update="false"/>
         <property name="segregated" access="field"
            column="segregate_offender_flag" type="yes_no"/>
      </subclass>
   </class>
</hibernate-mapping>


When I retrieve an Incident, loading of the offendersInvolved attribute looks like:
Code:
Hibernate: select offendersi0_.person_id as person_id__, offendersi0_.incident_id as incident4___, offendersi0_.person_id as person_id1_, offendersi0_.discipline_offender_flag as discipli6_1_, offendersi0_.offender_number as offender7_1_, offendersi0_.segregate_offender_flag as segregat8_1_, offendersi0_.version as version1_, offendersi0_.incident_id as incident4_1_, offendersi0_.injury_flag as injury_f5_1_, offender1_.offender_number as offender1_0_, offender1_.birthdate as birthdate0_, offender1_.facility_code as facility3_0_, offender1_.firstname as firstname0_, offender1_.fps_number as fps_number0_, offender1_.sex_code_type as sex_code6_0_, offender1_.surname as surname0_, offender1_.secondname as secondname0_ from persons_involved offendersi0_ left outer join offender offender1_ on offendersi0_.offender_number=offender1_.offender_number where offendersi0_.incident_id=?


The problem occurs when this query finds records in the persons_involved table that are not OffenderInvolved objects. Note that the generated query does not include the discriminator value '0001', even though I have force="true" on the discriminator element.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.