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