Hibernate:我可以使用 XML 和自定义生成器覆盖标识符生成器吗?
我想在我的应用程序中使用自定义序列生成器,但该实体位于与其他应用程序共享的域模型 jar 中。显然,实体注释可以在 orm.xml
中被覆盖,但我无法找出正确的 XML 咒语来使其正常工作。
我可以像这样修改实体中的注释:
@GenericGenerator(name = "MYGEN", strategy = "MyCustomGenerator")
@GeneratedValue(generator = "MYGEN")
但我需要以某种方式将其映射到 orm.xml
以便覆盖原始注释。在此处查看 orm.xml
架构 看来我什至无法指定除了“序列”和“表”之外的生成类型。
我应该提到,如果这很重要的话,我正在将 JPA 与 Hibernate 一起使用。
I want to use a custom sequence generator in my application, but the entity is located in a domain model jar that is shared with other applications. Apparently entity annotations can be overridden in orm.xml
but I can't figure out the proper XML incantation to get this to work.
I can modify the annotation in the entity like this this:
@GenericGenerator(name = "MYGEN", strategy = "MyCustomGenerator")
@GeneratedValue(generator = "MYGEN")
But I need to somehow map this to orm.xml
in order to override the original annotation. Looking at the orm.xml
schema here it appears that I can't even specify a generation type besides "sequence" and "table".
I should mention that I am using JPA with Hibernate, if that matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你看过hibernate注释文档吗?
https://docs.jboss.org/ hibernate/stable/annotations/reference/en/html/xml-overriding.html
它很好地解释了如何覆盖 orm xml 中的注释配置,
例如,考虑这个实体:
To override the ID field with a我使用的序列生成器:
Did you look at the hibernate annotations documentation?
https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/xml-overriding.html
It explains quite well how to override the annotation configurations in the orm xmls,
For exmaple, consider this entity:
To override the ID field with a sequence generator I used: