Wrong SQL-statement generation when where-attribute setting sentence contain Quoting
Description
Environment
None
Activity
Show:
Fabio MauloJuly 26, 2008 at 11:02 AM
The where tag must be written in SQL format that mean that you must quote the column name as your RDBMS need
In your case is
where="[ComponentType] = 'DOMAIN'"
BTW I don't understand why you are quoting all columns even if the column name is not a reserved word.
Remember <where> is part of the where clause in SQL format.
Who's Looking?
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="WEasy.Model" assembly="WEasy.Model">
<class name="WebSiteSolution" table="`WebSiteSolution`">
<id name="ID" column="`id`" >
<generator class="native" />
</id>
<property name="Name" column="`Name`" not-null="true" unique="true"/>
<property name="DemoUrl" column="`DemoUrl`" />
<property name="Order" column="`Order`" />
<property name="Description" column="`Description`" length="1000" />
<bag name="DomainTypes" table="`WebSiteSolution_Components`" where="`ComponentType` = 'DOMAIN'">
<key column="`WebSiteSolution_ID`" />
<composite-element class="SolutionComponent">
<property name="ComponentType" column="`ComponentType`" length="30">
<type name="WEasy.Utility.StringEnumUserType,WEasy.Utility">
<param name="enumClassName">WEasy.Model.SiteComponentType,WEasy.Model</param>
</type>
</property>
<many-to-one name="Component" class="SiteComponent" column="`SiteComponent_ID`" not-null="true"/>
</composite-element>
</bag>
</class>
</hibernate-mapping>
When fetching data nhibernate create a correct sql:
NHibernate.SQL: DEBUG LogCommand - SELECT domaintype0_.[WebSiteSolution_ID] as WebSiteS1__0, domaintype0_.[ComponentType] as Componen2_0_, domaintype0_.[SiteComponent_ID] as SiteComp3_0_ FROM [WebSiteSolution_Components] domaintype0_ WHERE domaintype0_.[ComponentType] = 'DOMAIN' and domaintype0_.[WebSiteSolution_ID]=@p0; @p0 = '1'
but when I call the collection.clear() method this result in nhibernate create a delete sql query:NHibernate.SQL: DEBUG LogCommand - DELETE FROM [WebSiteSolution_Components] WHERE [WebSiteSolution_ID] = @p0 AND `ComponentType` = 'DOMAIN'; @p0 = '1' It's a wrong sql query for sql server the `ComponentType`
do not be replace to [ComponentType]
Please check it.