Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nHibernate: Unable to locate persister

Tags:

nhibernate

Running VS2003, nHB 3.0.0.3001, trying to run a unit test through Gallio 3.2. The code is from the first session of "Summer of nHibernate". I am getting the following error when attempting to run the test.

NHibernate.HibernateException: Unable to locate persister: DataTransfer.Customer
TargetSite: Void OnLoad(NHibernate.Event.LoadEvent, NHibernate.Event.LoadType)
HelpLink: null
at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.Get(String entityName, Object id)
at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id)
at NHibernate.Impl.SessionImpl.Get[T](Object id)
at DataAccessLayer.NhibernateDataProvider.GetCustomerById(Int32 customerId) 

My very uneducated guess is that the Customer class cannot be seen. But both the unit test and the data access layers have a reference to the DataTransfer assembly that holds the Customer class. The Customer class is public and all the properties are public virtual.

The nHB config file is in the directory, and the Customer mapping file is an embedded resource. Seems to fail on the line:

return session.Get<Customer>(customerId);
like image 331
P Hemans Avatar asked Dec 03 '10 10:12

P Hemans


1 Answers

  1. Make sure your mapping file is named *.hbm.xml

  2. Make sure it is set to an embedded resource.

  3. If these fail, debug and when it fails, catch the exception and look at the InnerException - NHibernate has fantastic error messaging hidden in there.

Hope those thigs help out - otherwise we can look into some other options (but 1 and 2 solve 90% of persister problems)

like image 134
Bob Palmer Avatar answered Nov 13 '22 14:11

Bob Palmer