I see 3 variants:
- specify db constraints in schema (*.sql) file
- specify db constraints in ORM stuff(with xml/annotations/whatever)
- use mix of 1) and 2)
Is there any Best Practice for this topic?
Particularly, I’m interested in Hibernate world.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only constraints that are applied are the constraints that are in the database. Specifying constraints in Hibernate annotations is only useful if you’re using the hibernate tools to generate the database SQL schema from the Java source code. In the end, it always ends up being in the SQL.
So if you maintain the schema manually and don’t generate it from the Java annotations, using annotations to specify them is useless (except for documentation purposes).