如何使用camelCase将Hibernate实体字段映射到snake_case(下划线)数据库标识符 [英] How to map Hibernate entity fields using camelCase to snake_case (underscore) database identifiers

查看:33
本文介绍了如何使用camelCase将Hibernate实体字段映射到snake_case(下划线)数据库标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下划线的数据库字段.我有驼峰式实体字段.我无法更改其中任何一个.

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;

}

我的梦想:

@Entity
@DatabaseIsUnderscoreAndThisAnnotationConvertsThemToCamelCaseByDefault
public class AuthorisationEntity {

    private BigDecimal nonRecoverable;

    private BigDecimal supplierRecoverable;

    private BigDecimal refundAmount;

}

推荐答案

您可以使用 hibernate 的命名策略.此类命名策略类描述了如何为给定的 java 名称生成数据库名称.

You can use hibernate's naming strategy. Such naming strategy class describes how to generate database names for given java names.

见:

命名策略示例

第二个例子

非常好的 oracle 命名策略 - 它将骆驼转换为下划线约定,等等

very good oracle naming strategy - it converts camel to underscore convention, and much more

这篇关于如何使用camelCase将Hibernate实体字段映射到snake_case(下划线)数据库标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆