Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NHCD-39 - JetDriver: session.Refresh(...) -> wrong SQL-string ('join', 'where' and 'and' in wrong order). #7

Open
nhibernate-bot opened this issue May 19, 2017 · 0 comments

Comments

@nhibernate-bot
Copy link

Martin Gämperle created issue - 20/Sep/10 1:28 PM

Class hierarchy: 'B1' and 'B2' inherit from 'BBase'. 'A' has a list of 'B1's and a list of 'B2's as properties.

Mapping-file of A:

<class name="A" table="A" dynamic-update="true" lazy="false">
  <id name="SID" type="Int32" column="SID" unsaved-value="0">
    <generator class="hilo">
      <param name="max_lo">100</param>
    </generator>
  </id>
  <bag name="B1s" inverse="true" lazy="true" cascade="all-delete-orphan" batch-size="50">
    <key column="FK_A_SID"/>
    <one-to-many class="B1"/>
  </bag>
  <bag name="B2s" inverse="true" lazy="true" ascade="all-delete-orphan" batch-size="50">
    <key column="FK_A_SID"/>
    <one-to-many class="B2"/>
  </bag>
</class>

Mapping-file of BBase:

<class name="BBase" table="BBASE" discriminator-value="-1" dynamic-update="true" lazy="false">
  <id name="SID" type="Int32" column="SID" unsaved-value="0">
    <generator class="hilo">
    <param name="max_lo">100</param>
    </generator>
  </id>
  <discriminator column="TYPE" type="Int32" force="true"/>
  <many-to-one name="A" column="FK_A_SID" class="A" not-null="true"/>

  <!-- B1 -->
  <subclass name="B1" discriminator-value="0" lazy="false">
    ...
  </subclass>

  <!-- B2 -->
  <subclass name="B2" discriminator-value="1" lazy="false">
    ...
  </subclass>
</class>

When 'session.Refresh(A)' is called it produces an SQL-string that looks like this:
SELECT a.SID as ..., ..., b1s.FK_A_SID as ..., b1s.SID as ..., ... FROM A a LEFT OUTER JOIN BBASE b1s ON a.SID=b1s.FK_A_SID AND b1s.TYPE=0 WHERE a.SID=?

This SQL-string leads to an error. When I manually switch the 'AND' and 'WHERE' statements then it works:
SELECT a.SID as ..., ..., b1s.FK_A_SID as ..., b1s.SID as ..., ... FROM A a LEFT OUTER JOIN BBASE b1s ON a.SID=b1s.FK_A_SID WHERE a.SID=? AND b1s.TYPE=0

Remark: This happens only for the first bag in 'A's mapping-file.


Mark Junker added a comment - 21/Oct/11 8:17 PM

Using additional conditions in the JOIN .. ON .. clause is common practice in modern RDBMS and the SQL would execute just fine in those environments. I will take a look at this problem when I get to the point where I need sublcasses too (which may take some months).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant