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
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://nhibernate.info/doc/nh/en/index.html#manipulatingdata-querying