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

2008-04-28

Java Idioms for Hashing

It is common practice in Java for the calculation of a hash code to take every field into account, recursively descending into referenced objects.  In contexts where performance matters, this practice can be harmful.  The computation of the hash code in such fashion may actually be more expensive than a full equality check considering that hashing involves a lot of multiplications where equality testing involves only comparisons. 

Hashing is also used to divide objects into buckets.  For this purpose the extra cost is justified since one hash computation may eliminate many equality tests.  However, it is frequently not necessary to hash the entire reachable object graph to get a good hash code.  If an object's local non-reference fields show good variance in values across objects, it is adequate to hash them alone -- or even just a subset.  The most problematic case is "algebraic types", where the objects may large consist only of references to other objects.  Even in this case, one might still be able to get a decent hash by hashing only the object types a few levels into the object graph.  Limiting the depth of the traversal is also a reasonable strategy if the reachable object graph contains circular references.

Again, these observations only really matter when performance is a large consideration.  For small collections of objects from a small space, the extra think time is probably not worth the effort.  But, once again, it is shown that hashing is difficult.

2008-04-25

SQL Server vs CREATE TRIGGER

Using SQL Server 2000, a CREATE TRIGGER statement must be the first statement in a batch.  However, unlike other statements with that requirement, you cannot even put a SET XACT_ABORT ON statement in front of it.

2008-04-18

Determine File Extensions in Use

The following Mathematica code defines a function that lists all of the file extensions in use in a directory tree:

FileExtensionsInUse[directory_] := Module[{pattern="."~~Except["."|$PathnameSeparator]..~~EndOfString},
  StringCases[#, x:pattern:>x] /. {{}->"", {x_}:>x} & /@
  Select[FileNames["*", directory, Infinity], !StringFreeQ[#, pattern]&] //
  Union
]

2008-04-17

Ant vs Command Line Properties

Ant 1.7 appears to be sensitive to the order of command line options.  If you specify the build file (using -f) before specifying a property file (using -propertyfile), the build file will be loaded prior to loading the property file.  Thus, property values within the property file will not override those in the build file.  Reverse the order of the options if you want the property file to be loaded first.

2008-04-16

Mysterious Eclipse 3.3 Build Path Problems

Using Eclipse 3.3, I had a plug-in that failed to build with the error message complaining that a JAR on which it depends is missing.  The JAR was listed as an explicit, workspace-relative, library entry.  It was not listed in the plug-in manifest in any way.

I:

  •  verified that the destination resource existed
  • deleted the library entry and re-added it
  • cleaned and rebuilt the project
  • refreshed all resources in the workspace

None of these actions corrected the problem.  I eventually fixed it by temporarily adding the required JAR to the extra classpath entries in the plug-in manifest.  As soon as I did this, Eclipse tried to rebuild the project but failed complaining that there were now duplicate entries for the errant JAR.  I then removed the extra classpath entry that I had added and all was well.  Net result: no change.

I do not understand either what was broken or how it was fixed.  I can only imagine that Eclipse had some kind of cached information somewhere that finally got cleared out.

2008-04-11

Simulating Colour Blindness

Computerized simulation of color appearance for dichromats, by Hans Brettel, Francoise Vienot and John D. Mollon, is a paper that provides algorithms for transforming computer images so as to simulate the effects of various forms of colour blindness.

2008-04-05

DbFit

DbFit is a set of FIT/FitNesse fixtures for executing SQL tests.

Blog Archive