I've included my mappings below. I did enumerate the
Configuration.ClassMappings but I'm not really sure what to look at.
What I can tell you is that PackageConfiguration and
PackageConfigurationIdentifier were both mapped and present in the
ClassMappings. For the surrogate vs. composite key suggestion, the
key needs to be composite as this is a legacy table that I have no
control over.
One question I do have about composite keys is do I have to actually
map the composite key in an hbm file or is just declaring a composite
key in the object that uses it sufficient?
Here is the class mapping for PackageConfiguration...
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="ConfigurationManager.Domain"
namespace="ConfigurationManager.Domain">
<class name="PackageConfiguration" table="dbo.Generic" lazy="false"
>
<composite-id name="Identifier"
class="ConfigurationManager.Domain.PackageConfigurationIdentifier">
<key-property name="ConfigurationFilter" />
<key-property name="PackagePath" />
</composite-id>
<property name="ConfiguredValue" />
<property name="ConfiguredValueType" access="field.camelcase" />
</class>
</hibernate-mapping>
...And here is the mapping for the PackageConfigurationIdentifier...
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="ConfigurationManager.Domain"
namespace="ConfigurationManager.Domain">
<class name="PackageConfigurationIdentifier" table="dbo.Generic"
lazy="false">
<composite-id>
<key-property name="ConfigurationFilter" />
<key-property name="PackagePath" />
</composite-id>
</class>
</hibernate-mapping>
On Mar 16, 6:33 am, Jason Dentler <[email protected]> wrote:
> 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.- Hide quoted text -
>
> - Show quoted text -
--
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.