Drop unused field
Fix invalid comparator
Fix invalid null check
Handle nested managed sql sessions, and don't open a sql session if it is not handled properly