While working with hbncontainer I came across a bug which manifests itself when I run against MySQL. The following code, in the method size():
size = (Integer) getBaseCriteria().setProjection(
Projections.rowCount()).uniqueResult();
can cause problems, if the database returns the object as a Long (which MySQL does). So changing it to:
size = ((Number)getBaseCriteria().setProjection(
Projections.rowCount()).uniqueResult()).intValue();
solved the problem.