i have some problems with native queries in NHibernate 0.91.
When I try simple examples everything works fine.
For following mapping file (SQL Server 2000):
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="AddressType,DataLayer" table="address_type">
<id name="addressTypeId" column="address_type_id" type="Byte" >
<generator class="assigned"/>
</id>
<property name="name" column="name" type="String" not-null="true" length="50" />
</class>
</hibernate-mapping>
i can execute something like this:
Code:
IQuery q = sess.CreateSQLQuery("select {a.*} FROM address_type {a}", "a", typeof(AddressType));
IList tmp = q.List();
and everything works fine.
But when i tried some complicated example, mapping file with joined subclasses i have difficulties.
I tried mapping file that look something like this:
Code:
<class name="Communication, DataLayer" table="communication">
<id name="communicationId" column="communication_id" type="Int32" >
<generator class="assigned" />
</id>
<property name="commTypeId" column="comm_type_id" type="Byte" ></property>
<property name="ownerEntityId" column="owner_entity_id" type="Int32" ></property>
<property name="sortOrder" column="sort_order" type="Int32" ></property>
<property name="startDate" column="start_date" type="DateTime" ></property>
<property name="endDate" column="end_date" type="DateTime" ></property>
<joined-subclass name="Address, DataLayer" table="address">
<key column="communication_id" />
<property name="addressTypeId" column="address_type_id" type="Byte" ></property>
<property name="addressLine1" column="address_line1" type="String" ></property>
<property name="addressLine2" column="address_line2" type="String" ></property>
<property name="addressLine3" column="address_line3" type="String" ></property>
<property name="city" column="city" type="String" ></property>
<property name="state" column="state" type="String" ></property>
<property name="zipCode" column="zip_code" type="String" ></property>
<property name="country" column="country" type="String" ></property>
<property name="startDate" column="start_date" type="DateTime" ></property>
<property name="endDate" column="end_date" type="DateTime" ></property>
</joined-subclass>
</class>
and i try following code:
Code:
IQuery q = sess.CreateSQLQuery("select {e.*} FROM entity {e}",
"e", typeof(Entity));
IList tmp = q.List();
i got following exception:
Quote:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in nhibernate.dll
Additional information: System error.
Using SQL prifiler i traced query generated by NHibernate. First there is a problem with FROM clause becouse there is no space between last field in SELECT clause and FROM clause. When I correct this error and try to execute query i got a lot of errors in the form of:
Quote:
Server: Msg 107, Level 16, State 2, Line 1
The column prefix 'c_1_' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'c_2_' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'c_3_' does not match with a table name or alias name used in the query.
Server: Msg 107, Level 16, State 1, Line 1
The column prefix 'c_1_' does not match with a table name or alias name used in the query.
I suppose there is a problem with subclasses and native queries but i am not sure. Has anybody report similar problems.
And by the way: any expirience with full-text queries and NHibernate. I tried search on this forum but I didn't find anything useful.