Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL NHibernate
Hi,
I am trying to select something from DB using NHibernate, but it throws this error: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 5
 
Error At:
IQuery query = session.CreateQuery("FROM [Player] WHERE (([Pohlavi] = 'Muž') AND ([Aktivita] = 1)) ORDER BY [Tour_Points] DESC");
 
Select method:
public List<Player> Get_Player_Ranking_Men()
        {
            // ---------------------------------------------------------------------------------

            // setup nhibernate configuration
            NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
 
            config.SetProperty(NHibernate.Cfg.Environment.Dialect, "NHibernate.Dialect.MsSql2008Dialect");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
            config.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=PETA3NEC_NTBK;Initial Catalog=Beach_Volleyball;Integrated Security=True");
 
            // add our assembly
            config.AddAssembly("Entities");
 
            // setup nhibernate session
            NHibernate.ISessionFactory factory = config.BuildSessionFactory();
            NHibernate.ISession session = factory.OpenSession();
 
            // start nhibernate transaction
            NHibernate.ITransaction transaction = session.BeginTransaction();
 
            // ---------------------------------------------------------------------------------

            IQuery query = session.CreateQuery("FROM [Player] WHERE (([Pohlavi] = 'Muž') AND ([Aktivita] = 1)) ORDER BY [Tour_Points] DESC");
            List<Player> ListPlayer = query.List<Player>().ToList();
            return ListPlayer;
        }
 
Class Player:
public class Player
    {
        public virtual String Nickname { get; set; }
        public virtual String Jmeno { get; set; }
        public virtual String Prijmeni { get; set; }
        public virtual String Pohlavi { get; set; }
        public virtual String Play_by_Play_Name { get; set; }
        public virtual String Role { get; set; }
        public virtual DateTime Datum_Registrace { get; set; }
        public virtual int Tour_Points { get; set; }
        public virtual String Email { get; set; }
        public virtual Image Foto { get; set; }
        public virtual int Aktivita { get; set; }
    }
 
mapping document: Player.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="Entities"
                   assembly="Entities">
 
  <class name="Player" table="Player">
    <id name="Nickname" column="Nickname" type="string">
    </id>
 
    <property name="Jmeno"  column="Jmeno" type="string"/>
    <property name="Prijmeni"  column="Prijmeni" type="string"/>
    <property name="Pohlavi"  column="Pohlavi" type="string"/>
    <property name="Play_by_Play_Name"  column="Play_by_Play_Name" type="string"/>
    <property name="Role"  column="Role" type="string"/>
    <property name="Datum_Registrace"  column="Datum_Registrace" type="DateTime"/>
    <property name="Tour_Points"  column="Tour_Points" type="int"/>
    <property name="Email"  column="Email" type="string"/>
    <property name="Aktivita"  column="Aktivita" type="int"/>
  </class>
</hibernate-mapping>
 
Can anyone solve this error?
 
Thanks for replies!
 
-Pepin z Hane
Posted 14-Nov-12 3:17am
Comments
ryanb31 at 14-Nov-12 16:53pm
   
I believe it is a syntax issue. Did you run a profiler to see what the actual SQL getting executed was?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid