... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2008-04-30

Bug in Hibernate

In Hibernate 3.2.2, there appears to be a bug in org.hibernate.loader.custom.CustomLoader#scroll().  It calls the private method getHolderInstantiator():

static private HolderInstantiator getHolderInstantiator(ResultTransformer resultTransformer, String[] queryReturnAliases) {
    if ( resultTransformer != null ) {
        return HolderInstantiator.NOOP_INSTANTIATOR;
    }
    else {
        return new HolderInstantiator(resultTransformer, queryReturnAliases);
    }
}

The condition in the if statement appears to be reversed -- if a transformer is passed in it is ignored, otherwise it is used.  This bug turned up because I had registered a result transformer on the containing query.  It is still not fixed in the Hibernate source repository at the time of this writing.

The obvious workaround is to call the transformer yourself on each result row.  Unfortunately you must pass a list of result aliases to the transformTuple method of the transformer.  And how do you get that list?  You call Query.getReturnAliases of course.  But for an SQL query, you will get an UnsupportedOperationException, with the comforting message "SQL queries do not currently support returning aliases".

Blog Archive