-
Notifications
You must be signed in to change notification settings - Fork 934
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
Incorrect SQL generated fetching many-to-many with subclasses #3239
Comments
<set name="Sets" table="ahs2_property_set" cascade="save-update, persist">
<key column="property_id" />
<many-to-many class="Set" column="set_id" />
</set> Please provide mapping for Set class (with all subclasses if any). If I got it right the problem with fetching Sets property. |
Hi Bahusoid, Thanks for reaching out, you find the mapping of Set below. It is a little hard to provide all the subclasses because Set is very central to the code. BeWriter is not connected to Set and not as central. Also not connected to anything with subclasses. Please let me know if you need to look at BeWriter instead. When you read below mapping, please note that it is this part that relates to the table ahs2_property_set: <set name="SetProperties" table="ahs2_property_set" cascade="save-update, persist">
<key column="set_id" />
<many-to-many class="Property" column="property_id" />
</set> Best regards, Thomas === Set mapping === <?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" auto-import="false" namespace="Admc.Data.Ahs" assembly="Admc.Data, Version=3.5.9.0, Culture=neutral, PublicKeyToken=null" xmlns="urn:nhibernate-mapping-2.2">
<class name="Set" table="ahs2_set" abstract="true" dynamic-update="true" dynamic-insert="true">
<id name="Id" column="id" type="Int32">
<generator class="native" />
</id>
<discriminator>
<column name="set_type" length="50" not-null="true" sql-type="VARCHAR" />
</discriminator>
<property name="SetType" type="Admc.Data.EnumMapper`1[[Admc.Data.Ahs.SetType, Admc.Data, Version=3.5.9.0, Culture=neutral, PublicKeyToken=null]], Admc.Data, Version=3.5.9.0, Culture=neutral, PublicKeyToken=null" column="`set_type`" not-null="true" update="false" insert="false" />
<property name="Name" type="AnsiString" column="`name`" length="50" not-null="true" />
<set name="FieldSets" table="ahs2_set_field_set" cascade="save-update, persist">
<key column="set_id" />
<many-to-many class="FieldSet" column="field_set_id" />
</set>
<property name="Description" type="AnsiString" column="`description`" length="255" />
<set name="Properties" inverse="true" cascade="all,delete-orphan">
<key column="set_id" on-delete="cascade" />
<one-to-many class="SetProperty" />
</set>
<set name="SetProperties" table="ahs2_property_set" cascade="save-update, persist">
<key column="set_id" />
<many-to-many class="Property" column="property_id" />
</set>
<set name="GroupRoles" table="ahs2_apf_set_group_role">
<key column="set_id" />
<composite-element class="Admc.Data.Apf.GroupRole">
<many-to-one name="Role" column="role_id" not-null="true" foreign-key="FK_apf_group_role_role_id" />
<many-to-one name="Group" column="group_id" not-null="true" foreign-key="FK_apf_group_role_group_id" />
</composite-element>
</set>
</class>
</hibernate-mapping> |
I think I know what it's about. Though I have no time for debugging right now. If it's an option, you can try renaming |
Hi again, I think you have come up with something important :-) I can confirm that class SetProperty also uses property_id. (SetProperty is not a subclass to Set by the way, it's just another collection of properties related to sets). And when I looked at BeWriter it also uses the same columnname parent_id twice in its mapping. So relieved you could spot this so quickly! I could not see what BeWriter and Property had in common for several days... |
Fixed by #3252 |
Great work, thanks a lot! |
Hi,
I've been using NHibernate for many years and I like it very much, thank you everybody who is contributing!
When I upgraded from NHibernate.5.3.15 with net461 to NHibernate.5.4.0 with net48 two of my hundreds of mapped
entities (Property and BeWriter) could not be loaded anymore. The error was
NHibernate.Exceptions.GenericADOException : could not execute query
System.Data.SqlClient.SqlException : Incorrect syntax near ')'.
Invalid usage of the option FIRST in the FETCH statement.
The reason was that the sql query was incorrect. As you can see below the parentheses are incorrect and also
the alias sets2_1_ is not defined, it should have been sets2_.
For entity Property it looked like this:
=== SQL query ===
=== Database and Dialect ===
Database and dialect: I've tried
All with the same result.
=== The code I'm running ===
=== The mapping ===
I'm using Fluent NHibernate and the resulting mapping looks like this:
=== Database schema ===
The database schema is the following:
Thanks a lot for reading! I'm very grateful for any ideas on this problem :-)
Best regards, Thomas.
The text was updated successfully, but these errors were encountered: