I see a couple of things wrong with what you've shown us, but you left out the necessary information to solve the problem you asked about. Show us your mappings. Also, enumerate Configuration.ClassMappings and look at the ClassName property of each. This may give you some hints.
Building a new configuration and session factory probably adds a good 5 to 10 seconds to each of your queries. Build them once and reuse them. Use a surrogate key, not a composite key. This just needlessly complicates things. On Mon, Mar 15, 2010 at 9:28 PM, KN <[email protected]> wrote: > I am trying to write a generic repository for my classes using > NHibernate. I have my only hbm.xml file marked as Embedded Resource. > In the following code, the GetAll() method works just fine, however > the Get(TIdentifier identifier) does not. For this method, I receive > the error message... No persister for: > ConfigurationManager.Interface.IPackageConfiguration. > > This is my generic repository... > > public class PackageConfigurationRepository<TIdentifier, TEntity> > where TEntity : class > { > > public IList<TEntity> GetAll() > { > ISessionFactory sessionFactory = new > Configuration().Configure().BuildSessionFactory(); > ISession session = sessionFactory.OpenSession(); > > ICriteria criteria = session.CreateCriteria<TEntity>(); > IList<TEntity> query = criteria.List<TEntity>(); > > return query; > } > > public TEntity Get(TIdentifier identifier) > { > ISessionFactory sessionFactory = new > Configuration().Configure().BuildSessionFactory(); > ISession session = sessionFactory.OpenSession(); > > return session.Get<TEntity>(identifier); <=FAILS HERE WITH > ABOVE ERROR MSG > } > > } > > > This is how I call the generic repository... > > static public void GetById() > { > IPackageConfigurationIdentifier identifier = new > PackageConfigurationIdentifier(); > > identifier.ConfigurationFilter = "ID1"; > identifier.PackagePath = "ID2"; > > NoGenericRepository noGenericRepository = new > NoGenericRepository(); > IPackageConfiguration configuration = > noGenericRepository.Get(identifier); > > > PackageConfigurationRepository<IPackageConfigurationIdentifier, > IPackageConfiguration> repository = > new > PackageConfigurationRepository<IPackageConfigurationIdentifier, > IPackageConfiguration>(); > > configuration = repository.Get(identifier); > > } > > static public void GetAll() <= WORKS FINE > { > > PackageConfigurationRepository<IPackageConfigurationIdentifier, > IPackageConfiguration> repository = > new > PackageConfigurationRepository<IPackageConfigurationIdentifier, > IPackageConfiguration>(); > > IList<IPackageConfiguration> configs = > repository.GetAll(); > > } > > So how does it work for the GetAll() method, but fails for the > GetById() method? > > Thanks, > > Kyle > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
