-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Strange behaviour in UniqueResult
PostPosted: Mon Mar 26, 2007 11:38 am 
Contributor
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 1:04 pm 
Contributor
Contributor

Joined: Tue May 30, 2006 1:25 am
Posts: 29
For this case the solution was
<class name="HumanResourceInfo" table="HumanResources" mutable="false" polymorphism="explicit">

and
<class name="HumanResourceVisualInfo" table="HumanResources" mutable="false" polymorphism="explicit">

Problem solved.
Bye.

_________________
Fabio Maulo.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.