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

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

问题描述

我在下划线中有数据库字段。我在camelcase中有实体字段。我不能改变其中任何一个。

I have database fields in underscore. I have entity fields in camelcase. I can't change either of those.

是否有一些东西,可能是一个类级别的注释我可以用来默认实体列名注释到camelcase等价物?

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命名策略 - 它将camel转换为下划线约定,以及更多

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

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

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