views:

89

answers:

3

Hi,

I cannot understand why this simple query is not created. I call this method from a test and it throws an exception complaining about line 1, column 7 where I cannot see anything wrong.

    public IList<Continent> GetContinentByName(string name)
      {
       ISession session = GetSession();

       IQuery query = 
                         session.CreateQuery("select from Continent where Continent.ContinentShort='Atlantis'");

// (........) Next step will be getting the list from the query if I can make it work

I get antlr exception below

TestCase 'M:DataAccessLayer.HibernateDataProvider.GetContinentByName(System.String)' failed: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 7 NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column 7

Any suggestions?

Thanks

+1  A: 

session.CreateQuery expexts a HQL query, like this: sess.CreateQuery("from DomesticCat cat where cat.Name in (:namesList)");

If you are trying to push a native SQL query you must do this: session.CreateSQLQuery("SELECT {cat.*} FROM CAT {cat} WHERE ROWNUM<10", "cat", typeof(Cat))

However, that would not be a good way to use NHibernate.

See Nhibernate docs for more info:http://nhforge.org/doc/nh/en/index.html#manipulatingdata-querying

Per-Frode Pedersen
+1  A: 

I think it's expecting an alias where you have provided the full entity name. Try:

IQuery query = session.CreateQuery("from Continent c where c.ContinentShort='Atlantis'");

If this doesn't fix the problem please show the mapping for Continent.

Jamie Ide
A: 

O.K.

the problem is the 'select' at the beginning. Seems it is not valid in the version I am using. So once I have removed the "Select" at the beginning, it worked fine!

burak ozdogan