SOS-2244 Use persistence when possible
SOS-2244 Rewrite custom sql to avoid subselects
SOS-2244 Autogenerated