I have a problem when using Hibernate Criteria API:
var query = session.QueryOver<MyClass>().Where(param => param.Name == "myFilterName").List<MyClass>();
If a run this statement, a NHibernate.QueryException is thrown:
could not resolve property: Name of: MyClass
And in the StackTrace:
at NHibernate.Persister.Entity.AbstractPropertyMapping.ToType(String propertyName)
MyClass.hbm.xml file has the property mapped of this way:
<property name="name" access="field">
<column name="NAME" length="50" not-null="true" />
</property>
I think that the problem comes because hibernate can not access the property "Name" of MyClass because is mapped with access="field"
, but I can not change this way to access the property due application design requirements.
The idea is create querys by using Criteria API with lambda expressions in order to avoid hardcoded string property names.
Also I´ve tried with a Expression with the same exception result:
var criterion = Expression.Where<MyClass>(param => param.Name == "myFilterName");
var result = session.CreateCriteria<MyClass>().Add(criterion).List<MyClass>();
Somebody knows how I can indicate to Criteria API that MyClass has the properties mapped as access="field"
?
Help very appreciated.
, but requires change all property names for each hbm.xml file(in my case I use one xml file for each entity). Another approach is set the access only one time in the class declaration of this way: