I have database fields in underscore. I have entity fields in camelcase. I can’t change either of those.
Is there something, maybe a class level annotation I can use to default entity column name annotations to the camelcase equivalent?
for example, I have an entity like this:
@Entity public class AuthorisationEntity { @Column(name = "non_recoverable") private BigDecimal nonRecoverable; @Column(name = "supplier_recoverable") private BigDecimal supplierRecoverable; @Column(name = "refund_amount") private BigDecimal refundAmount; }
I dream of this:
@Entity @DatabaseIsUnderscoreAndThisAnnotationConvertsThemToCamelCaseByDefault public class AuthorisationEntity { private BigDecimal nonRecoverable; private BigDecimal supplierRecoverable; private BigDecimal refundAmount; }
Advertisement
Answer
You can use hibernate’s naming strategy. Such naming strategy class describes how to generate database names for given java names.
See:
very good oracle naming strategy – it converts camel to underscore convention, and much more