I know that it is possible to name them Foreing Keys
and also manually define the constraints, but isn't there a way to define a naming policy for each type of constraint and thus avoid the random identifiers that Spring generates by default?
eg for a constraint of typeUNIQUE
, Spring generates the following name:UK_ob8kqyqqgmefl0aco34akdtpe
but I don't know if it is possible to somehow define the following pattern:AK_TABLE_ATTRIBUTE
so that Spring uses it every time it generates that type of constraint.
The foregoing more than anything to standardize the restrictions and facilitate their maintenance.
As you comment, there is
@javax.persistence.ForeignKey
:But if you want to change the naming strategy in general, I found this: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
This class allows you to define the name of the elements of your database, from the name of the tables, columns to the foreign keys. It's really an extension of the hibernate implementation :