Is there a way to tell JPA / Hibernate to convert column names from camcel to _s?

Is there a general way to tell JPA / Hibernate to convert all form column names to form:

EMAILADDRESS

to the form:

email_address

?

I would prefer not to use the @Column annotation for hundreds of columns. Hope someone thought about it;)

+4
source share
1 answer

See Hibernate Reference Documenation - 3.6. Implementing NamingStrategy

The org.hibernate.cfg.NamingStrategy interface allows you to specify "standard naming" for database objects and schema elements.

You can provide rules for automatically creating a database of identifiers from Java identifiers or for processing a "logical" column and table names specified in the mapping file in a "physical" table and column names. This function helps to reduce the verbosity of the cartographic document, eliminating repetitive noise (TBL_ for example, prefixes). By default, the strategy used by Hibernate is quite minimal. You can specify a different strategy by calling Configuration.setNamingStrategy () before adding the mappings: ...

See also: http://www.javalobby.org/java/forums/t19838.html

+3
source

Source: https://habr.com/ru/post/1311701/


All Articles