Search failed [SQL: SQL not available]

Hi guys, by adding Hibernate to my project I got this error

this is a mistake ~

Exception thrown: 'NHibernate.Exceptions.GenericADOException' in NHibernate.dll

Additional information: Unable to perform find[SQL: SQL not available]

      

error image

http://i.stack.imgur.com/UYI9W.png

this code after editing (doesn't work either)

public ICollection<T> GetAllRecords()
        {
            using (var session = HibernateHelper.OpenSession)
            {
                var Kero = session.CreateCriteria(typeof(T)).List<T>();
                if (Kero == null)
                {
                    Kero = session.CreateCriteria(typeof(T)).List<T>();
                }
                return Kero;
            }
        }

      

before editing

public ICollection<T> GetAllRecords()
        {
            using (var session = HibernateHelper.OpenSession)
                return session.CreateCriteria(typeof(T)).List<T>();
        }

      

and this class

namespace Phoenix.Hibernate
{
    using NHibernate.Criterion;
    using System.Collections.Generic;

    /// <summary>
    /// This class encapsulates a repository for a table in the server database. The class contains a group of
    /// background methods for processing database transactions, inherited by other table repository classes 
    /// defined in the calling server project.
    /// </summary>
    /// <typeparam name="T">The table domain structure being processed by the class.</typeparam>
    public abstract class Repository<T> where T : class
    {
        /// <summary>
        /// This method returns true if the key specified in the method arguments has a corresponding value in the
        /// server database. If the value could not be found using the specified key, this method will return false.
        /// </summary>
        /// <param name="key">The key being searched for.</param>
        public bool ContainsKey(object key)
        {
            using (var session = HibernateHelper.OpenSession)
                return session.Get<T>(key) != null;
        }

        /// <summary>
        /// This method returns true if the key specified in the method arguments has a corresponding value in the
        /// server database. If the value could not be found using the specified key, this method will return false.
        /// The object specified in the method arguments will be assigned a new value if the value exists.
        /// </summary>
        /// <param name="key">The key being searched for.</param>
        public bool TryGetValue(object key, out T obj)
        {
            using (var session = HibernateHelper.OpenSession)
                obj = session.Get<T>(key);
            return obj != null;
        }

        /// <summary>
        /// This method returns the row entry for an object if the key specified in the method arguments is found in 
        /// the server database. If the value could not be found using the specified key, this method will null.
        /// </summary>
        /// <param name="key">The key being searched for.</param>
        public T GetByIdentifier(object key)
        {
            using (var session = HibernateHelper.OpenSession)
                return session.Get<T>(key);
        }

        /// <summary>
        /// This method fills a general collection object with entries from the database. The entries added to
        /// the collection are defined by criteria specified in the method arguments.
        /// </summary>
        /// <param name="property">The property name for the column to search by.</param>
        /// <param name="value">The value to search for in the column specified.</param>
        public ICollection<T> GetUniqueResults(string property, object value)
        {
            using (var session = HibernateHelper.OpenSession)
                return session.CreateCriteria(typeof(T)).Add(Restrictions.Eq(property, value)).List<T>();
        }

        /// <summary>
        /// This method fills a general collection object with specific entries from the database. The entries 
        /// added to the collection are defined by criteria specified in the method arguments.
        /// </summary>
        /// <param name="property1">The property name for the column to search by.</param>
        /// <param name="value1">The value to search for in the column specified.</param>
        /// <param name="property2">The property name for the column to search by.</param>
        /// <param name="value2">The value to search for in the column specified.</param>
        public ICollection<T> GetUniqueResults(string property1, object value1, string property2, object value2)
        {
            using (var session = HibernateHelper.OpenSession)
                return session.CreateCriteria(typeof(T))
                    .Add(Restrictions.Eq(property1, value1)).Add(Restrictions.Eq(property2, value2)).List<T>();
        }

        /// <summary> This method returns a collection containing all entries from the database table. </summary>
        public ICollection<T> GetAllRecords()
        {
            using (var session = HibernateHelper.OpenSession)
                return session.CreateCriteria(typeof(T)).List<T>();
        }

        /// <summary>
        /// This method returns the first entry found in the database table that matches the search criteria 
        /// specified in the method arguments. If the result was not found, the method will return null.
        /// </summary>
        /// <param name="property">The property name for the column to search by.</param>
        /// <param name="value">The value to search for.</param>
        public T GetUniqueResult(string property, object value)
        {
            using (var session = HibernateHelper.OpenSession)
                return session.CreateCriteria(typeof(T)).Add(Restrictions.Eq(property, value)).UniqueResult<T>();
        }

        /// <summary>
        /// This method accepts a SQL query as a formatted string from the method arguments, and executes the
        /// query. Error handling should be handled by the parent function. 
        /// </summary>
        /// <param name="query">The formatted SQL query string.</param>
        public int ExecuteSQLQuery(string query)
        {
            using (var session = HibernateHelper.OpenSession)
                return session.CreateSQLQuery(query).ExecuteUpdate();
        }
    }
}

      

can anyone help me ?!

+3


source to share





All Articles