Named queries with nHibernate

I have a lot of problems getting named queries to work with nHibernate. My last problem is getting the error "request cannot be completed" without additional information. Are there any complete examples that I can download from somewhere, because all the sample tutorials and documentation provide snippets of code, but only half the story about how to make it work.

Here is the code that gives me problems.

Class

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Model.Entities { public class TableInfo { public string TABLENAME { get; set; } public string COLUMNNAME { get; set; } #region Overrides public override int GetHashCode() { int result = TABLENAME.GetHashCode(); result += COLUMNNAME.GetHashCode(); return result; } public override bool Equals(object obj) { if (obj == null) return false; TableInfo dict = (TableInfo)obj; return dict.TABLENAME.IsEqual(this.TABLENAME) && dict.COLUMNNAME.IsEqual(this.COLUMNNAME); } #endregion } } 

Mapping file

 <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Model.Entities" assembly="Model" default-lazy="false"> <class name="Model.Entities.TableInfo, Model" table="UIM_TableColumnInfo"> <composite-id> <key-property name="TABLENAME" column="TABLENAME" type="string"></key-property> <key-property name="COLUMNNAME" column="COLUMNNAME" type="string"></key-property> </composite-id> </class> <sql-query name="GetTableInfo"> <return alias="tableInfo" class="Model.Entities.TableInfo, Model"> <return-property name="TABLENAME" column="TABLENAME"/> <return-property name="COLUMNNAME" column="COLUMNNAME"/> </return> <![CDATA[ select info.tci_table_name TABLENAME , info.tci_column_name COLUMNNAME from ALL_TAB_COLS c ,( select 'DATE' TYPE_NAME, 'D' data_type_ind from dual union select 'NUMBER','N' from dual union select 'VARCHAR2','S' from dual ) ct , UIM_TableColumnInfo info where c.DATA_TYPE = ct.TYPE_NAME (+) and c.column_id is not null and UPPER(c.TABLE_NAME) = :TableName and UPPER(c.COLUMN_NAME) = UPPER(info.tci_column_name (+)) order by c.column_id ]]> </sql-query> </hibernate-mapping> 

Call code

 public List<TableInfo> GetTableInfo(string tableName) { return m_TableInfoRepository .NamedQuery("GetTableInfo") .SetString("TableName", tableName) .List<TableInfo>() as List<TableInfo>; } 
+4
source share
3 answers

I assume that you tested before SQL in your client database, so I think that maybe we should see what happens inside, so I can recommend these links to you;

Hope this helps.

+2
source

Maybe I'm wrong, but it looks like it could be a conflict between the table "TABLENAME" and the parameter: TableName, what happens if you try to use a different parameter name?

0
source

The internal exception must contain the actual sql that was generated and tried to execute. Paste this into the database query and run it directly in the database. This will help you. It will be much easier if you know why SQL cannot be executed.

0
source

All Articles