Contributor |
 |
Joined: Tue May 30, 2006 1:25 am Posts: 29
|
Hibernate version: Svn
Mapping documents:
<class name="HumanResourceInfo" table="HumanResources" mutable="false">
<id name="Id" type="Guid">
<generator class="assigned"/>
</id>
<property name="Name" length="50"/>
<property name ="Code" type="Int32"/>
</class>
<class name="HumanResourceVisualInfo" table="HumanResources" mutable="false">
<id name="Id" type="Guid">
<generator class="assigned"/>
</id>
<property name="Name" length="50"/>
<property name ="Code" type="Int32"/>
<property name="Photo" type="BinaryBlob"/>
</class>
Code between sessionFactory.openSession() and session.close():
NHibernate.Expression.DetachedCriteria criteria = NHibernate.Expression.DetachedCriteria.For(typeof(HumanResourceInfo));
criteria.Add(NHibernate.Expression.Expression.Eq("Code", 123));
using (ISession session = OpenSession())
{
try
{
ICriteria c = criteria.GetExecutableCriteria(session);
result = c.UniqueResult<HumanResourceInfo>();
}
finally
{ session.Close(); }
}
Pre-condition:
In table HumanResources there is only one record with column assigned to value 123.
In the implementation the class HumanResourceVisualInfo inherit it's behaviour from HumanResourceInfo.
NH throw: NonUniqueResultException
The problem is in SessionFactoryImpl.GetImplementorClasses.
In the mapping there isn't a relation between class HumanResourceInfo and class HumanResourceVisualInfo but NH ask to NET if there is a relation and create 2 SQL one for HumanResourceInfo and the other for HumanResourceVisualInfo.
Note : I can't use lazy loading for property Photo.
I think NH must discover reletion between classes using the mapping and not using reflection.
Any way... Is there a way to query only HumanResourceInfo using criteria ?
_________________ Fabio Maulo.
|
|