Disagree with all the previous answers:
I would recommend manually performing all necessary validation checks before executing the persistence or database operation. For example, verify whether related entities exist or any foreign key dependencies are present. If a violation is detected, you can throw an IllegalStateException or a custom exception that clearly indicates the issue. This approach ensures that your business logic is handled explicitly in your service layer rather than relying on database constraints to handle errors.
Refference: https://stackoverflow.com/a/77125211/16993210