Hibernate实体字段camelcase,数据库下划线 [英] Hibernate entity fields camelcase, database underscore

查看:167
本文介绍了Hibernate实体字段camelcase,数据库下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下划线的数据库字段。我在camelcase中有实体字段。



是否有某种东西,或许是我可以使用的默认实体列名称注释,与camelcase等价的注释?

>

例如,我有一个这样的实体:

  @Entity 
public class AuthorisationEntity {

@Column(name =non_recoverable)
private BigDecimal nonRecoverable;

@Column(name =supplier_recoverable)
private BigDecimal supplierRecoverable;

@Column(name =refund_amount)
私人BigDecimal refundAmount;

}

我梦寐以求:

  @Entity 
@DatabaseIsUnderscoreAndThisAnnotationConvertsThemToCamelCaseByDefault
public class AuthorisationEntity {

private BigDecimal nonRecoverable;

private BigDecimal supplierRecoverable;

私人BigDecimal refundAmount;



解决方案

使用hibernate的命名策略。这种命名策略类描述了如何为给定的java名称生成数据库名称。



请参阅:

命名策略示例



第二个示例 a>



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


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;

}

解决方案

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

See:

naming strategy example

second example

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

这篇关于Hibernate实体字段camelcase,数据库下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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