Fixes to query that creates entity