Applied newOrm patch contributed by Y. Kotlyarov