Hibernate:在运行时根据映射生成类

发布于 2024-12-22 19:31:16 字数 79 浏览 5 评论 0原文

有没有办法基于Hibernate映射生成域类?我期待有关 hbm2java 工具的答案,但它被设计为在构建时使用。是否可以在运行时执行此类任务?

Is there a way to generate domain classes based on Hibernate mapping? I anticipate answers about hbm2java tool, but it is designed to be used in build time. Is it possible to perform such task at runtime?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏有森光若流苏 2024-12-29 19:31:16

简短的回答:这可能是可能的,但通常不是一个好主意。

Hibernate 和其他 ORM 库旨在成为应用程序中数据库和面向对象域之间的桥梁。如果您想在运行时生成域,那么您就否定了拥有域或使用 Hibernate 的全部原因。老实说,Hibernate 的设计初衷并不是为了做到这一点。

但是,如果您想要一个工具来调查模式并报告存在哪些表、列等结构,我建议使用常规 sql。

正如您所提到的,如果您想从一组 .hbm.xml 文件生成域,请使用 hbm2java 工具并利用生成的代码。

Short answer: this may be possible, but generally not a good idea.

Hibernate and other ORM libraries are meant to be a bridge between a database and a object oriented domain in your application. If you want to generate your domain during runtime, you would negate the whole reason for having a domain or using Hibernate. Honestly, Hibernate was not designed to do this.

However, if you want a tool to investigate a schema and report back on what tables, columns, etc structure exists I would suggest using regular sql.

As you mentioned, if you want to generate a domain off of a set of .hbm.xml files, use the hbm2java tool and leverage the generated code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文