I am following along with the Summer of NHibernate Screencast Series and am running into a strange NHibernate Exception.
NHibernate.Hql.Ast.ANTLR.QuerySyntaxException:
Exception of type
'Antlr.Runtime.NoViableAltException' was thrown.
[select from DataTransfer.Person p where p.FirstName=:fn].
I have deviated from the Screencast Series in the following ways:
- Running against an MS SQL Server Compact Database
- I am using MSTest instead of MbUnit
I've tried any number of combination of queries always with the same result. My present CreateQuery syntax
public IList<Person> GetPersonsByFirstName(string firstName)
{
ISession session = GetSession();
return session.CreateQuery("select from Person p " +
"where p.FirstName=:fn").SetString("fn", firstName)
.List<Person>();
}
While not a direct query this method works
public Person GetPersonById(int personId)
{
ISession session = GetSession();
return session.Get<Person>(personId);
}
My hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="BookDb">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.connection_string">Data Source=C:\Code\BookCollection\DataAccessLayer\BookCollectionDb.sdf</property>
<property name="show_sql">true</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="DataTransfer"/>
</session-factory>
</hibernate-configuration>
Person.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataTransfer" namespace="DataTransfer">
<class name="DataTransfer.Person,DataTransfer" table="Person">
<id name="PersonId" column="PersonId" type="Int32" unsaved-value="0">
<generator class="native"/>
</id>
<property name="FirstName" column="FirstName" type="String" length="50" not-null="false" />
<property name="LastName" column="LastName" type="String" length="50" not-null="false" />
</class>
</hibernate-mapping>