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 4: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)

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 299
2 BillWoodruff 174
3 /\jmot 170
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100