first, I want you to understand that hql and criteria both support
polymorphic querying. In other words the thing from which you query
does not have to be mapped, and we will instead query from all entity
class which implement the named interface or extend from the named class
('from java.lang.Object' and 'from java.lang.Comparable' are both valid
queries).
So consider this just another restriction on the result set, find all
implementers of said interface/class.
Now, like I said I am fine with logging a warning in the case where you
try to query from a interface/class for which there are no entities
which are implementers. But treating this any differently than a query
which returns zero results for other reasons is not valid imo.
Note that if this is important enough of a distinction to you you can
always perform the checking yourself using
org.hibernate.engine.SessionFactoryImplementor#getImplementors
So that if I were to try 'from java.lang.Comparable', but
( ( SessionFactoryImplementor )
factory ).getImplementors( java.lang.Comparable.class ) returned an
empty array you'd have this situation about whcih you are concerned.
-
Steve Ebersole
Project Lead
http://hibernate.org
steve(a)hibernate.org
Principal Software Engineer
JBoss, a division of Red Hat
http://jboss.com
http://redhat.com
steve.ebersole(a)jboss.com
steve.ebersole(a)redhat.com
On Tue, 2009-02-17 at 10:57 -0800, Kevin Wong wrote:
Hi Steve, thanks for the idea. Thoughts on returning null instead of
an empty list to differentiate an unsuccessful query versus a successful query that
returns no items.
Kevin
----- Original Message -----
From: "Steve Ebersole" <steve(a)hibernate.org>
To: "Kevin Wong" <siliconvalleykevin(a)gmail.com>
Cc: hibernate-dev(a)lists.jboss.org
Sent: Monday, February 16, 2009 7:18:23 AM GMT -08:00 US/Canada Pacific
Subject: Re: [hibernate-dev] SessionImpl.list(CriteriaImpl criteria) returns an empty
list when no implementors exist
We could perhaps log.warn like we do for HQL, but throwing an exception
is not a good idea imo.
-
Steve Ebersole
Project Lead
http://hibernate.org
steve(a)hibernate.org
Principal Software Engineer
JBoss, a division of Red Hat
http://jboss.com
http://redhat.com
steve.ebersole(a)jboss.com
steve.ebersole(a)redhat.com
On Sat, 2009-02-14 at 09:29 -0800, Kevin Wong wrote:
> Hi all, in using hibernate v31final SessionImpl.list(CriteriaImpl criteria), I had
an issue where hibernate would return an empty list when no implementors existed for the
entity name(I had mistaken deleted the entity from the hibernation configuration file).
The confusion arose in that this was be mistaken for a query that would return no rows. In
looking at the code, it appears that the results list is always initialized to an empty
list rather than null. Likewise, no exception is thrown if the entity does not exists,
whereas when using HQL an org.hibernate.hql.ast.QuerySyntaxException exception would be
thrown. Opinions on initializing the results list to null or throwing an exception if the
implementators exist for the desired entity?
>
> Thanks
> Kevin
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/hibernate-dev
_______________________________________________
hibernate-dev mailing list
hibernate-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev