Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate: No persister for NHibernate.Criterion.SqlFunctionProjection

Tags:

nhibernate

I am using NHibernate version 2.0.0.4000.

In one of my queries I wanted to make use of the sql function dateadd to add a number of days. This wasn't registered so I created my own dialect and registered the function as follows:

RegisterFunction("adddays", 
    new SQLFunctionTemplate(NHibernateUtil.DateTime, 
    "dateadd(dd, ?1, ?2)"));

The registration gets hit and seems to work fine. I use the function in a DetachedCriteria query as follows:

...
Restrictions.LtProperty("DateColumn1"
    Projections.SqlFunction("adddays", NHibernateUtil.DateTime,
        Projections.Constant(days),
        Projections.Property("DateColumn2"))
...

The criteria is returned from a method and passed of to another query. Upon the execution of the final query I get the following exception:

NHibernate.MappingException was caught
  Message="No persister for: NHibernate.Criterion.SqlFunctionProjection"
  Source="NHibernate"
  StackTrace:
       at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName,
            Boolean throwIfNotFound)
       at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName)
       ...

None of the blog posts that I have seen mention this problem. Can anybody help?

Cheers in advance. Nige.

like image 244
Nigel Avatar asked Jun 09 '09 11:06

Nigel


2 Answers

Solved it.

The problem was caused by my usage elsewhere of Restrictions.Eq rather than Restrictions.EqProperty. The former does not have an overload for (IProjection,IProjection) and so was treating the second projection as an object and passing it to a persister.

Thanks to anyone who investigated this. Nigel.

like image 59
Nigel Avatar answered Nov 16 '22 01:11

Nigel


For No Persister exception in nhibernet solution is

just give a right click on the respective hbm file ->Properties->change the type Build Action-> to Embedded Resource

with the above step application will working fine

like image 21
vamsi krishna Avatar answered Nov 16 '22 01:11

vamsi krishna