简体   繁体   English

Hibernate:基于运行时的映射生成类

[英]Hibernate: generate classes based on mappings in runtime

Is there a way to generate domain classes based on Hibernate mapping? 有没有办法基于Hibernate映射生成域类? I anticipate answers about hbm2java tool, but it is designed to be used in build time. 我期待有关hbm2java工具的答案,但它被设计用于构建时。 Is it possible to perform such task at runtime? 是否可以在运行时执行此类任务?

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. Hibernate和其他ORM库旨在成为应用程序中数据库和面向对象域之间的桥梁。 If you want to generate your domain during runtime, you would negate the whole reason for having a domain or using Hibernate. 如果要在运行时生成域,则可以否定拥有域或使用Hibernate的全部原因。 Honestly, Hibernate was not designed to do this. 老实说,Hibernate不是为此而设计的。

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. 但是,如果您想要一个工具来调查架构并报告存在哪些表,列等结构,我建议使用常规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. 如前所述,如果要从一组.hbm.xml文件生成域,请使用hbm2java工具并利用生成的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM