Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 333659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:58:55+00:00 2026-05-12T09:58:55+00:00

I’m doing some per table inheritance and all is working great- but I’m noticing

  • 0

I’m doing some per table inheritance and all is working great- but I’m noticing that when I want the base entity (base table data) NHProf is showing a left outter join on the child entity / (related table)

How can I set the default behavior to only query the needed data – for example: When I want a list of parent elements (and only that data) the query only returns me that element.

right now my mapping is similar to the below:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="FormBase, ClassLibrary1" table="tbl_FormBase">
    <id name="BaseID" column="ID" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="ImportDate" column="ImportDate" type="datetime" not-null="false" />
    <joined-subclass table="tbl_Form" name="Form, ClassLibrary1">
      <key column="ID"/>
      <property name="gendate" column="gendate" type="string" not-null="false" />
    </joined-subclass>
  </class>
</hibernate-mapping>

And the example where I want all the data back vs ONLY the parent entity is shown below:

    Dim r As New FormRepository()
    Dim forms As List(Of Form) = r.GetFormCollection().ToList()



    Dim fbr As New FormBaseRepository()
    Dim fb As List(Of FormBase) = fbr.GetFormBaseCollection().ToList()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:58:55+00:00Added an answer on May 12, 2026 at 9:58 am

    You can’t. It’s called “implicit polymorphism” and it’s a rather nice (albeit unwanted in your case 🙂 ) feature provided by Hibernate. When you query a list of base objects, the actual instances returned are of the actual concrete implementations. Hence the left join is needed for Hibernate to find out whether particular entity is a FormBase or a Form.

    Update (too big to fit in comment):
    The general issue here is that if you were to trick Hibernate into loading only the base entity you may end up with inconsistent session state. Consider the following:

    1. Form instance (that is persisted to both form_base and form tables) was somehow loaded as FormBase.
    2. You’ve deleted it.
    3. During flush Hibernate (which thinks we’re dealing with FormBase and thus is blissfully unaware that there are 2 tables involved) issues a DELETE FROM form statement which throws an exception as FK is violated.

    Implicit polymorphism exists to prevent that from happening – Form is always a Form, never a FormBase. You could, of course, use “table-per-hierarchy” mapping where everything is in the same table and thus no joins are needed but you’ll end up with (potentially) a lot of NULL columns and – ergo – inability to specify not-null on children’s properties.

    All that said, if this is REALLY a huge performance issue for you (which it normally shouldn’t be – presumably it’s an indexed join), you could try using a native query to just return FormBase instances.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.