These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: native queries and joined subclasses
PostPosted: Mon Aug 29, 2005 2:22 pm 
Newbie

Joined: Mon Aug 29, 2005 11:35 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Wed Sep 06, 2006 11:57 am 
Newbie

Joined: Fri Mar 17, 2006 5:23 pm
Posts: 6
I have exactly the same problem. In a nutshell, a concrete subclass is spread over two tables (table-per-subclass mapping strategy). Is it possible to fetch instances of this subclass via createSQLQuery()?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.