Hy,

I have a problem with querying using SQL syntax
This is my AR object
    [ActiveRecord("Documents")]
    public class Document : ActiveRecordBase
    {
       
        private int _docId;
       
        private string _title;
       
        private string _description;
       
        private string _format;
       
        private int _size;
       
        private System.Byte [] _content;
       
       // private System.Collections.IList _docClauseValues;
       
     //   private System.Collections.IList _CollectiveAgreementPropertyValues;
       
        private CollectiveAgreement _collectiveAgreement;
       
        private DocType _docType;

        private int _docStatus;

        public Document()
        {
        }

        public Document(string _title, string _description, string _format, int _size, byte[] _content,  CollectiveAgreement _collectiveAgreement, DocType _docType, int _docStatus)
        {
            this._title = _title;
            this._description = _description;
            this._format = _format;
            this._size = _size;
            this._content = _content;
            this._collectiveAgreement = _collectiveAgreement;
            this._docType = _docType;
            this._docStatus = _docStatus;
        }

        [PrimaryKey(PrimaryKeyType.Native)]
        public int DocId
        {
            get
            {
                return this._docId;
            }
            set
            {
                this._docId = value;
            }
        }
       
        [Property()]
        public string Title
        {
            get
            {
                return this._title;
            }
            set
            {
                this._title = value;
            }
        }
       
        [Property()]
        public string Description
        {
            get
            {
                return this._description;
            }
            set
            {
                this._description = value;
            }
        }
       
        [Property(Length = 3)]
        public string Format
        {
            get
            {
                return this._format;
            }
            set
            {
                this._format = value;
            }
        }
       
        [Property()]
        public int Size
        {
            get
            {
                return this._size;
            }
            set
            {
                this._size = value;
            }
        }
       
        [Property(ColumnType="BinaryBlob",Length=2147483647)]
        public System.Byte[] Content
        {
            get
            {
                return this._content;
            }
            set
            {
                this._content = value;
            }
        }
       
       
        [BelongsTo("CaId")]
        public CollectiveAgreement CollectiveAgreement
        {
            get
            {
                return this._collectiveAgreement;
            }
            set
            {
                this._collectiveAgreement = value;
            }
        }
       
        [BelongsTo("DocTypeId")]
        public DocType DocType
        {
            get
            {
                return this._docType;
            }
            set
            {
                this._docType = value;
            }
        }
       
        [Property()]
        public int DocStatus
        {
            get { return _docStatus; }
            set { _docStatus = value; }
        }

        public static void DeleteAll()
        {
            ActiveRecordBase.DeleteAll(typeof(Document));
        }
       
        public static Document[] FindAll()
        {
            return ((Document[])(ActiveRecordBase.FindAll(typeof(Document))));
        }
       
        public static Document Find(int DocId)
        {
            return ((Document)(ActiveRecordBase.FindByPrimaryKey(typeof(Document), DocId)));
        }

        public static Document FindMainDocumentForCA(CollectiveAgreement ca)
        {
            return ((Document)(ActiveRecordBase.FindOne(typeof(Document),_expression_.Eq("CollectiveAgreement",ca),_expression_.Eq("DocStatus",1))));
        }

        public static Document[] QuickSearch(string query)
        {
            QuickSearchDocument q = new QuickSearchDocument();
            q.query = query;
            return (Document[]) ExecuteQuery(q);
        }
    }

    public class QuickSearchDocument:ActiveRecordBaseQuery
    {
        public string query;

        public QuickSearchDocument(): base(typeof(Document))
        {
           
        }
        public override object Execute(ISession session)
        {
            IQuery q = session.CreateSQLQuery("select * from Documents where contains(Content,?)",
                "Document",typeof(Document));
            q.SetString(0,query);
            return base.GetResultsArray(typeof(Document),q.List(),null,false);
           
        }
    }


When I'm executing the QuickSearch(string query) it gives me this error

TestCase 'lrisPrj.Tests.CollectiveAgreementTests.Test_QuickSearch '
failed: Castle.ActiveRecord.Framework.ActiveRecordException : Could not perform Execute for Document
  ----> NHibernate.ADOException : error in FindBySQL
  ----> System.IndexOutOfRangeException : DocId0_
    at Castle.ActiveRecord.ActiveRecordBase.ExecuteQuery(IActiveRecordQuery q)
    lris\models\document.cs(218,0): at Lris.Models.Document.QuickSearch(String query)
    e:\projects\lris\lrisprj.tests\collectiveagreementtests.cs(220,0): at lrisPrj.Tests.CollectiveAgreementTests.Test_QuickSearch()
    --ActiveRecordException
    at NHibernate.Impl.SessionImpl.FindBySQL(String sqlQuery, String[] aliases, Type[] classes, QueryParameters queryParameters, ICollection querySpaces)
    at NHibernate.Impl.SqlQueryImpl.List()
    lris\models\document.cs(243,0): at Lris.Models.QuickSearchDocument.Execute(ISession session)
    at Castle.ActiveRecord.ActiveRecordBase.ExecuteQuery(IActiveRecordQuery q)
    --ADOException
    at System.Data.Common.FieldNameLookup.GetOrdinal(String fieldName)
    at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
    at NHibernate.Driver.NHybridDataReader.GetOrdinal (String name)
    at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name)
    at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
    at NHibernate.Loader.Loader.GetKeyFromResultSet(Int32 i, ILoadable persister, Object id, IDataReader rs, ISessionImplementor session)
    at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies)
    at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
    at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections (ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
    at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
    at NHibernate.Impl.SessionImpl.FindBySQL(String sqlQuery, String[] aliases, Type[] classes, QueryParameters queryParameters, ICollection querySpaces)


Can someone help mey with this one?
I want to do the full-text search with MS SQL Server so that's way I did go with CreateSQLQuery.
Thanks,
Mircea
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
CastleProject-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/castleproject-users

Reply via email to