-->
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.  [ 2 posts ] 
Author Message
 Post subject: Joined-Subclass prevent outer joins
PostPosted: Mon Jan 08, 2007 9:11 pm 
Newbie

Joined: Mon Jan 08, 2007 8:40 pm
Posts: 1
Question:
I have two objects, Person and Organization, that inherit from Entity. My database tables match the structure of these objects.

Whenever I get a list of all Entity objects, Hibernate creates outer joins to the Person and Organization tables.

I am wondering how I might prevent Hibernate from automatically creating these joins, thus returning a list of the base Entity object only.

Any assistance would be greatly appreciated.

Hibernate version:
1.2.0.1001

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="TestApp.Model.Entity, TestApp.Model" table="entity">
      <id name="Id" column="entity_id" type="Int32" unsaved-value="-1">
         <generator class="increment"/>
      </id>

      <discriminator column="entity_class_code" type="String"/>
      <property name="DeterminerCode" column="entity_determiner_code" />
      <property name="Name" column="entity_name" />
      <bag name="PlayedRoles" lazy="true">
         <key column="player_entity_id"/>
         <one-to-many class="TestApp.Model.Role, TestApp.Model"/>
      </bag>
      <bag name="Addresses" lazy="true">
         <key column="entity_id"/>
         <one-to-many class="TestApp.Model.EntityTelecomAddress, TestApp.Model"/>
      </bag>

   </class>
   <joined-subclass name="TestApp.Model.Person, TestApp.Model"
              extends="TestApp.Model.Entity, TestApp.Model"
              proxy ="TestApp.Model.Person, TestApp.Model"
              table="person"
              lazy="true">
      <key column="entity_id"/>
      <property name="EducationLevelCode" column="education_level_code" />
      <property name="MaritalStatusCode" column="marital_status_code" />
      <property name ="AdministrativeGenderCode" column="gender_code" />
      <property name ="BirthTime" column="birth_date_time" />
      <property name ="DeceasedInd" column="deceased_indicator" />
      <property name ="DeceasedTime" column="deceased_time" />
      <property name ="OrganDonorInd" column="organ_donor_indicator" />
   </joined-subclass>
   <joined-subclass name="TestApp.Model.Organization, TestApp.Model"
              extends="TestApp.Model.Entity, TestApp.Model"
              proxy ="TestApp.Model.Organization, TestApp.Model"
              table="organization"
              lazy="true">
      <key column="entity_id"/>
      <property name="StandardIndustryClassCode" column="industry_class_code" />
   </joined-subclass>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
IList<Entity> list = s.CreateCriteria(typeof(Entity)).List<Entity>();

I also tried
Code:
IList<Entity> list = s.CreateQuery("select from Entity").List<Entity>();


Name and version of the database you are using:
MySQL 5

The generated SQL (show_sql=true):
Code:
NHibernate: SELECT this_.entity_id as entity1_0_, this_.entity_name as entity4_2_0_, this_.entity_determiner_code as entity3_2_0_, this_1_.education_level_code as education2_3_0_, this_1_.marital_status_code as marital3_3_0_, this_1_.gender_code as gender4_3_0_, this_1_.birth_date_time as birth5_3_0_, this_1_.deceased_indicator as deceased6_3_0_, this_1_.deceased_time as deceased7_3_0_, this_1_.organ_donor_indicator as organ8_3_0_, this_2_.industry_class_code as industry2_4_0_, case when this_1_.entity_id is not null then 1 when this_2_.entity_id is not null then 2 when this_.entity_id is not null then 0 end as clazz_0_ FROM entity this_ left outer join person this_1_ on this_.entity_id=this_1_.entity_id left outer join organization this_2_ on this_.entity_id=this_2_.entity_id


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 3:31 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate will not load just a part of an object, but you can query for the ids only, then the joins should not happen:
Code:
select e.id from Entity e

Or try using CreateQuery(...).Enumerable() instead - this will cause a id-only query to be executed, and individual objects will be loaded one by one when iterating through the returned IEnumerable.


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

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.