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: HQL query joined-subclass // many-to-one
PostPosted: Tue Dec 19, 2006 10:01 am 
Newbie

Joined: Tue Sep 26, 2006 8:08 am
Posts: 3
Hibernate version: 1.2.0

I have the folowing mapping files:

Code:
  <class name="Kooijman.AtSchool.Domain.Relations.Relation, Kooijman.AtSchool.Domain" lazy="false" table="Relation">
    <id name="Id" access="nosetter.camelcase-underscore" column="Id" type="Guid" unsaved-value="{00000000-0000-0000-0000-000000000000}">
      <generator class="guid.comb" />
    </id>
    <version name="Version" column="Version" type="timestamp" />
    <property name="SearchName" type="String" column="SearchName" length="100" />
    <property name="DisplayName" type="String" column="DisplayName" length="100" />
    <many-to-one name="LicenseHolder" class="Kooijman.AtSchool.Domain.Common.LicenseHolder, Kooijman.AtSchool.Domain" column="LicenseHolderId" cascade="none" />
    <component name="ModifyLog">
      <property name="InsertDate" type="DateTime" column="InsertDate" />
      <property name="ModifyDate" type="DateTime" column="ModifyDate" />
      <property name="Deleted" type="Boolean" column="Deleted" />
      <many-to-one name="Inserter" class="Kooijman.AtSchool.Domain.Common.SystemUser, Kooijman.AtSchool.Domain" column="InserterId" cascade="none" />
      <many-to-one name="Modifier" class="Kooijman.AtSchool.Domain.Common.SystemUser, Kooijman.AtSchool.Domain" column="ModifierId" cascade="none" />
    </component>
  </class>


Code:
  <joined-subclass name="Kooijman.AtSchool.Domain.Relations.Person, Kooijman.AtSchool.Domain" lazy="false" extends="Kooijman.AtSchool.Domain.Relations.Relation, Kooijman.AtSchool.Domain" table="Person">
    <key column="Id" />
    <property name="Initials" type="String" column="Initials" length="24" />
    <property name="FirstNames" type="String" column="FirstNames" length="200" />
    <property name="CallName" type="String" column="CallName" length="28" />
    <property name="LastName" type="String" column="LastName" length="200" not-null="true" />
    <property name="FamilyName" type="String" column="FamilyName" length="200" />
    <property name="Gender" type="Kooijman.AtSchool.Domain.Common.SystemObjects.Gender, Kooijman.AtSchool.Domain" column="Gender" />
    <property name="BirthDate" type="DateTime" column="BirthDate" />
    <property name="BirthTown" type="String" column="BirthTown" length="40" />
    <property name="CitizenServiceNumber" type="String" column="CitizenServiceNumber" length="9" />
    <many-to-one name="LastNamePrefix" class="Kooijman.AtSchool.Domain.Common.SystemObjects.LastNamePrefix, Kooijman.AtSchool.Domain" column="LastNamePrefix" cascade="none" />
    <many-to-one name="BirthCountry" class="Kooijman.AtSchool.Domain.Common.SystemObjects.Country, Kooijman.AtSchool.Domain" column="BirthCountryId" cascade="none" />
    <many-to-one name="Nationality" class="Kooijman.AtSchool.Domain.Common.SystemObjects.Nationality, Kooijman.AtSchool.Domain" column="NationalityId" cascade="none" />
    <many-to-one name="CountryOfOrigin" class="Kooijman.AtSchool.Domain.Common.SystemObjects.Country, Kooijman.AtSchool.Domain" column="CountryOfOriginId" cascade="none" />
    <many-to-one name="MaritalStatus" class="Kooijman.AtSchool.Domain.Common.SystemObjects.MaritalStatus, Kooijman.AtSchool.Domain" column="MaritalStatusId" cascade="none" />
    <many-to-one name="Denomination" class="Kooijman.AtSchool.Domain.Common.ApplicationObjects.Denomination, Kooijman.AtSchool.Domain" column="DenominationId" cascade="none" />
    <set name="PersonTypes" lazy="false" inverse="true" generic="true">
      <key column="Id" />
      <one-to-many class="Kooijman.AtSchool.Domain.Relations.PersonType, Kooijman.AtSchool.Domain" />
    </set>
  </joined-subclass>


Code:
  <class name="Kooijman.AtSchool.Domain.Relations.PersonType, Kooijman.AtSchool.Domain" lazy="false" table="PersonType">
    <id name="Id" access="nosetter.camelcase-underscore" column="Id" type="Guid" unsaved-value="{00000000-0000-0000-0000-000000000000}">
      <generator class="guid.comb" />
    </id>
    <version name="Version" column="Version" type="timestamp" />
    <property name="Share" type="Boolean" column="Share" not-null="true" />
    <many-to-one name="LicenseHolder" class="Kooijman.AtSchool.Domain.Common.LicenseHolder, Kooijman.AtSchool.Domain" column="LicenseHolderId" not-null="true" />
    <many-to-one name="Person" class="Kooijman.AtSchool.Domain.Relations.Person, Kooijman.AtSchool.Domain" column="PersonId" not-null="true" cascade="all" />
    <component name="ModifyLog">
      <property name="InsertDate" type="DateTime" column="InsertDate" />
      <property name="ModifyDate" type="DateTime" column="ModifyDate" />
      <property name="Deleted" type="Boolean" column="Deleted" />
      <many-to-one name="Inserter" class="Kooijman.AtSchool.Domain.Common.SystemUser, Kooijman.AtSchool.Domain" column="InserterId" cascade="none" />
      <many-to-one name="Modifier" class="Kooijman.AtSchool.Domain.Common.SystemUser, Kooijman.AtSchool.Domain" column="ModifierId" cascade="none" />
    </component>
  </class>


Code:
  <joined-subclass name="Kooijman.AtSchool.Domain.Relations.Sibling, Kooijman.AtSchool.Domain" lazy="false" extends="Kooijman.AtSchool.Domain.Relations.PersonType, Kooijman.AtSchool.Domain" table="Sibling">
    <key column="Id" />
    <property name="PlaceInFamily" type="Int32" column="PlaceInFamily" />
    <many-to-one name="CurrentSchool" class="Kooijman.AtSchool.Domain.Relations.School, Kooijman.AtSchool.Domain" column="CurrentSchoolId" cascade="none" />
  </joined-subclass>


Code:
  <joined-subclass name="Kooijman.AtSchool.Domain.Relations.Student, Kooijman.AtSchool.Domain" lazy="false" extends="Kooijman.AtSchool.Domain.Relations.Sibling, Kooijman.AtSchool.Domain" table="Student">
    <key column="Id" />
    <property name="EducationNumber" type="String" column="EducationNumber" length="9" />
    <property name="PersonalNumber" type="String" column="PersonalNumber" length="9" />
    <property name="InTheNetherlandsSince" type="DateTime" column="InTheNetherlandsSince" />
    <property name="StartDatePs" type="DateTime" column="StartDatePs" />
    <property name="StartDateDl" type="DateTime" column="StartDateDl" />
    <many-to-one name="HomeLanguage" class="Kooijman.AtSchool.Domain.Common.SystemObjects.Language, Kooijman.AtSchool.Domain" column="HomeLanguageId" not-null="true" cascade="none" />
    <many-to-one name="SecondNationality" class="Kooijman.AtSchool.Domain.Common.SystemObjects.Nationality, Kooijman.AtSchool.Domain" column="SecondNationalityId" cascade="none" />
  </joined-subclass>


Code:
  <class name="Kooijman.AtSchool.Domain.LinkObjects.RelationLink, Kooijman.AtSchool.Domain" lazy="false" table="RelationLink">
    <id name="Id" access="nosetter.camelcase-underscore" column="Id" type="Guid" unsaved-value="{00000000-0000-0000-0000-000000000000}">
      <generator class="guid.comb" />
    </id>
    <version name="Version" column="Version" type="timestamp" />
    <property name="StartDate" type="DateTime" column="StartDate" />
    <property name="ClosingDate" type="DateTime" column="ClosingDate" />
    <many-to-one name="FirstRelation" class="Kooijman.AtSchool.Domain.Relations.Relation, Kooijman.AtSchool.Domain" column="FirstRelationId" cascade="none" />
    <many-to-one name="SecondRelation" class="Kooijman.AtSchool.Domain.Relations.Relation, Kooijman.AtSchool.Domain" column="SecondRelationId" cascade="none" />
    <component name="ModifyLog">
      <property name="InsertDate" type="DateTime" column="InsertDate" />
      <property name="ModifyDate" type="DateTime" column="ModifyDate" />
      <property name="Deleted" type="Boolean" column="Deleted" />
      <many-to-one name="Inserter" class="Kooijman.AtSchool.Domain.Common.SystemUser, Kooijman.AtSchool.Domain" column="InserterId" cascade="none" />
      <many-to-one name="Modifier" class="Kooijman.AtSchool.Domain.Common.SystemUser, Kooijman.AtSchool.Domain" column="ModifierId" cascade="none" />
    </component>
  </class>


Code:
  <joined-subclass name="Kooijman.AtSchool.Domain.LinkObjects.StudentSchoolLink, Kooijman.AtSchool.Domain" lazy="false" extends="Kooijman.AtSchool.Domain.LinkObjects.RelationLink, Kooijman.AtSchool.Domain" table="StudentSchoolLink">
    <key column="Id" />
    <property name="StudentNumber" type="Int32" column="StudentNumber" />
    <property name="FirstEducationDate" type="DateTime" column="FirstEducationDate" />
    <many-to-one name="Student" class="Kooijman.AtSchool.Domain.Relations.Student, Kooijman.AtSchool.Domain" column="StudentId" cascade="all" fetch="join" />
    <many-to-one name="School" class="Kooijman.AtSchool.Domain.Relations.School, Kooijman.AtSchool.Domain" column="SchoolId" cascade="none" />
    <many-to-one name="Establishment" class="Kooijman.AtSchool.Domain.Relations.Establishment, Kooijman.AtSchool.Domain" column="EstablishmentId" cascade="none" />
    <many-to-one name="StudentType" class="Kooijman.AtSchool.Domain.Common.ApplicationObjects.StudentType, Kooijman.AtSchool.Domain" column="StudentTypeId" cascade="none" />
  </joined-subclass>


As you can see the structure is:

- Person object is inherited from Relation object

- Student object is inherited from Sibling object which is inherited from PersonType object

- Persontype object has a many-to-one to the Person object

- StudentSchoolLink object is inherited from the RelationLink object

I tried to query to get all StudentSchoolLink object for the students with lastname = 'name'. The folowing query I used:

from StudentSchoolLink s where s.Student.Person.LastName = 'name'

The sql query generated is:

Code:
select
   studentsch0_.Id as Id39_,
   studentsch0_.StudentNumber as StudentN2_40_,
   studentsch0_.FirstEducationDate as FirstEdu3_40_,
   studentsch0_.StudentId as StudentId40_,
   studentsch0_.SchoolId as SchoolId40_,
   studentsch0_.EstablishmentId as Establis6_40_,
   studentsch0_.StudentTypeId as StudentT7_40_,
   studentsch0_1_.Version as Version39_,
   studentsch0_1_.StartDate as StartDate39_,
   studentsch0_1_.ClosingDate as ClosingD4_39_,
   studentsch0_1_.FirstRelationId as FirstRel5_39_,
   studentsch0_1_.SecondRelationId as SecondRe6_39_,
   studentsch0_1_.InsertDate as InsertDate39_,
   studentsch0_1_.ModifyDate as ModifyDate39_,
   studentsch0_1_.Deleted as Deleted39_,
   studentsch0_1_.InserterId as InserterId39_,
   studentsch0_1_.ModifierId as ModifierId39_
from
   StudentSchoolLink studentsch0_
   inner join RelationLink studentsch0_1_ on studentsch0_.Id=studentsch0_1_.Id,
   Student student1_,
   Person person2_ left outer join Relation person2_1_ on person2_.Id=person2_1_.Id
where
   person2_.LastName='name' 
   and studentsch0_.StudentId=student1_.Id
   and student1_2_.PersonId=person2_.Id


This query gives an exception, the created sql query is not correct. There is a problem with the PersonType object (student1_2_.PersonId is incorrect).

Anyone suggestions what I do wrong?

Marc


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.