动态命名表与休眠 [英] Dynamic Naming Table with Hibernate

查看:90
本文介绍了动态命名表与休眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hibernate有可能动态地设置表名和实体类中提到的带有注释的字段。我发现这就是所谓的命名策略,但我不太明白。
首先,我想知道有什么可能的解决方案来动态定义表的名称以及字段的名称?
其次,有人可以向我解释类ImprovedNamingStrategy的主要作用,并举例说明使用。

解决方案

从Java持久化与休眠 - 您可以扩展 ImprovedNamingStrategy 类(实现 NamingStrategy 接口并提供默认行为)和重写方法

public String tableName(String tableName){
返回YourTableName;
}



还有其他方法。
希望这有助于!!


Is it possible with hibernate to set dynamically the name of table and the fields mentioned in the entity class with annotations. I found that is something called naming strategy but I didn't understand it well. First, I wondered what are the possible solutions to dynamically define the name of table as well as the name of fields? Second, can someone explain to me the main role of the class ImprovedNamingStrategy and cite an example of use.

解决方案

From "Java Persistence with hibernate" - You can extend ImprovedNamingStrategy class (Which implements NamingStrategy interface and provides default behavior) and override methods

public String tableName(String tableName) { return "YourTableName"; }

There are other methods as well. Hope this helps!!

这篇关于动态命名表与休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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