[hibernate-dev] SessionImpl.list(CriteriaImpl criteria) returns an empty list when no implementors exist

Bruno Bieth biethb at gmail.com
Mon Mar 7 05:51:35 EST 2011


@Steve Ebersole

Hi Steve,

I came across the same problem regarding the SessionImpl.list returning an
empty list, and I ended up on this thread. I don't really understand your
reasoning here :

 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).

I get that we need to be able to return implementors for classes that are
not mapped (to support polymorphic queries). But it doesn't mean that we
can't fail when no implementors are found, does it ?

What would be the implications of throwing an exception when SessionImpl
cannot find any implementors for a given query ?
Consider the following code :
*
    public List list(CriteriaImpl criteria) throws HibernateException {
        errorIfClosed();
        checkTransactionSynchStatus();
        String[] implementors = factory.getImplementors(
criteria.getEntityOrClassName() );
        int size = implementors.length;

        if( size == 0 ) {
              throw new IllegalStateException("no mapping found for class
..")
        }
        // ....*


Performing a search on Object.class would still work (given that we've got
at least a class mapped and registered) ?

Regards,
Bruno Bieth



More information about the hibernate-dev mailing list