views:

2414

answers:

3

I am having a great deal of trouble getting named queries to work with nHibernate. My latest problem is getting the error message "could not execute query" with no additional information. Are there any complete examples I can download from somewhere because all the tutorials and documentation examples provide code snippits but only tell half the story about getting it to work.

Here is the code that is giving 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>

Calling Code

public List<TableInfo> GetTableInfo(string tableName)
{
    return m_TableInfoRepository
        .NamedQuery("GetTableInfo")
        .SetString("TableName", tableName)
        .List<TableInfo>() as List<TableInfo>;
}
A: 

Can you post the code?

nmiranda
A: 

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

I'm new to NHibernate but I want to help and learn, please don't vote me down.

nmiranda
I tried this but made no difference.
Craig
+2  A: 

I assume that you have tested before the SQL in your client database, so I think that maybe we should see what is happening inside, so I can recommend you this links;

  1. Named Query Error
  2. Using NHibernate and Log4Net in ASP.NET 2.0 applications
  3. How do I view the SQL that is generated by nHibernate?

Hope it helps.

nmiranda