Your approach isn't very well designed cause you are violating the separation of concern principle.
Your entity shouldn't know anything about databases or statements or similar cause its not responsible for that.
Drop that validation parts from your entity and go for another solution.
I would create a unique validation rule like here
And handle this constraints in your controller like here
Hope this helps