Hi,
I have an Employee class. A property of this class is Manager which is also of the Employee type. The Employee is derived from the Contact class. This two classes correspond with two separate tables in the database: Contact and Employee. These tables have separate primary keys: EmployeeId 10 can correspond with ContactId 5 for example.
This looks like a table-per-subclass strategy, but the primary key values are not identical.
When I get all instances of this class (see stack trace), I get an exception 'No row with the given identifier exists'. I guess this could lie in the fact that I didn't map the EmployeeId, but where should I do that?
I made a joined-subclass element in my mapping (see underneath) but I don't have to the possibility to map the EmployeeId. The <id> element is not present in the joined-subclass. I could make a many-to-one relationship so that Contact becomes a property of Employee, but then I would lose the benefits of inheritance and I have to wrap the functionality of the Contact class into the Employee class. I would not like that.
Could anyone help me with this mapping problem?
Greets,
Nils
Hibernate version: 1.2.0
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyProject.Domain" namespace="MyProject.Domain">
<joined-subclass name="Employee" extends="Contact" lazy="false" table="Employee" >
<key column="ContactID" />
<many-to-one name="Manager" column="ManagerID" class="Employee" />
</joined-subclass>
</hibernate-mapping>
Full stack trace of any exception that occurs:
[UnresolvableObjectException: No row with the given identifier exists: 21, of class: MyProject.Domain.Employee]
NHibernate.UnresolvableObjectException.ThrowIfNull(Object o, Object id, Type clazz) +88
NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id, Boolean eager, Boolean isNullable) +137
NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session) +99
NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session, Object owner) +112
NHibernate.Impl.SessionImpl.InitializeEntity(Object obj) +410
NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session) +355
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +905
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +85
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +81
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +58
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) +165
NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session) +80
NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results) +487
NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) +123
NHibernate.Impl.CriteriaImpl.List() +112
Name and version of the database you are using: SQL Server 2005
|