特定于包的 Hibernate NamingStrategy
鉴于大型应用程序的不同包中存在多个 Hibernate 实体,我想确保不存在命名冲突。例如,包 foo 中可能有一个 Person
-Entity,而包 bar 中可能有另一个 Person
-Entity。
现在这两个实体应该映射到这样的表名称:
foo.Person --> FOO_PERSON bar.Person --> BAR_PERSON
我可以使用 @Table-annotation 来实现这一点:
@Table(name="FOO_PERSON")
public class Person ...
@Table(name="BAR_PERSON")
public class Person ...
但是,我想使用某种 NamingStrategy,它会自动执行此操作。 Hibernate 提供了接口 org.hibernate.cfg.NamingStrategy。我尝试扩展 DefaultNamingStrategy
,但是(尽管文档另有说明)您只能获得类的非限定名称,因此没有有关包名称的信息。
有一个 JIRA 问题(http://opensource.atlassian.com/projects/hibernate /browse/HHH-4312)关于这个问题。鉴于它自 2007 年以来一直开放,我正在寻找一种解决方法或完全不同的方法。有什么想法吗?
Given several Hibernate entities in different packages of a large application, I like to make sure, that there are no naming conflicts. E.g. there could be a Person
-Entity in package foo and another Person
-Entity in package bar.
Now this two entities should map to table names like this:
foo.Person --> FOO_PERSON bar.Person --> BAR_PERSON
I could use the @Table-annotation to achieve this:
@Table(name="FOO_PERSON")
public class Person ...
@Table(name="BAR_PERSON")
public class Person ...
However, I'd like to use some kind of NamingStrategy, that does this automatically. Hibernate offers the interface org.hibernate.cfg.NamingStrategy
. I tried to extend the DefaultNamingStrategy
, however (despite the documentation stating otherwise) you only get the unqualified name of the class and therefore no information about the package name.
There is a JIRA issue (http://opensource.atlassian.com/projects/hibernate/browse/HHH-4312) about this problem. Given, that it is open since 2007, I'm looking for a work-around or a totally different approach. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这些包位于不同的项目模块中,您可以尝试将它们放入不同的架构中。这样,它们的表名可能会相同,而您不会在意。只是一个想法。
If these packages are in different project modules, you could try putting them in different schemas. This way they table names could end up the same and you wouldn't care. Just a thought.