How does hibernate generate foreign key constraint names?
If i do not define a name hibernate generates something like this
CONSTRAINT fk_2ocepcfwpr1v18dg1ieoe6bau
how is this name generated? Maybe from MD5
hash of field names or something like that? I need to know if the name is equal on all instances.
Hibernate generates a constraint name by concatenating table and properties names and convert the result to
MD5
. It is needed, because of the constraint names length restriction in some databases. For an example, in the Oracle database, a foreign key name length can't be more than 30 symbols length.This code snippet from Hibernate source org.hibernate.mapping.Constraint
You can generate your own constraint names (unique and foreign key) using
ImplicitNamingStrategy
. You can refer Hibernate5NamingStrategy , as an example.