Replaced dynamic queries with criteria API