Improved logging. Fixed critical error when getting nextId for a new entity if entity is already generated.