简体   繁体   English

是否可以为Java类自动生成Hibernate映射?

[英]Is it possible to automatically generate Hibernate mappings for Java classes?

I'd like to automatically generate Hibernate mappings for some Java classes I have. 我想为我拥有的某些Java类自动生成Hibernate映射。 Basically, I'd like all objects in the class to have the equivalent of the @OneToOne annotation, and all collections to have the equivalent of the @OneToMany annotation by default. 基本上,我希望类中的所有对象都具有与@OneToOne注释等效的对象,并且所有集合在默认情况下都具有与@OneToMany注释等效的@OneToMany I'd like to be able to fine-tune this later, but 99% of my data works this way, and it would take a very long time to go through all the classes and add the annotations manually. 我希望以后可以对此进行微调,但是我99%的数据都可以通过这种方式工作,并且遍历所有类并手动添加注释将花费很长时间。

Is this possible? 这可能吗?

edit: Sorry, I think omitted something very important: I'd actually like to generate these default annotations from classes, not from a database. 编辑:对不起,我认为省略了一些非常重要的内容:我实际上想从类而不是从数据库生成这些默认注释。 I would still have to design about 40 tables if I were to start with the database, but I already have a package containing all those classes. 如果要从数据库开始,我仍然必须设计大约40个表,但是我已经有一个包含所有这些类的包。 Is it possible to generate the proper mappings based on existing Java classes? 是否可以基于现有的Java类生成适当的映射?

Yes, in eclipse there is a plugin called hibernate tools from jboss, which can generate mapping from a existing database. 是的,在eclipse中有一个来自jboss的名为hibernate tools的插件,可以从现有数据库生成映射。

You can generate all hibernate files both xml and annotations variant. 您可以生成所有休眠文件,包括xml和注释变体。

Just Google Hibernate Tools to know how to use it. 只是Google Hibernate Tools知道如何使用它。

Thanks !! 谢谢 !!

If you are creating new classes then you can create the database structure first and then create classes using database. 如果要创建新类,则可以先创建数据库结构,然后再使用数据库创建类。 In eclipse, hibernate provides Hibernate code generation feature. 在eclipse中,hibernate提供了Hibernate代码生成功能。 You can use that. 您可以使用它。

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

相关问题 Hibernate:基于运行时的映射生成类 - Hibernate: generate classes based on mappings in runtime 生成持久性映射->通过休眠映射不可用Intellij - Generate persistence mappings -> by hibernate mappings not available Intellij 是否可以使用Mojo的Hibernate插件生成带注释的Java类? - Is it possible to generate Annotated Java classes using Mojo's Hibernate plug-in? 从复杂的 json 自动生成 java 类 - Automatically generate java classes from complex json 使用库/工具从干净的Java类/ POJO自动生成JPA XML映射 - Auto-generate JPA XML mappings from clean Java classes / POJOs using library/tool 从.Net DLL自动生成Java包装器类 - Automatically Generate java wrapper classes from .Net DLL 是否可以为 Java 11 和 java 模块生成 hibernate 元模型? - Is it possible to generate hibernate metamodel for Java 11 and java modules? Java Spring Hibernate,运行时(可选)执行映射? - Java Spring Hibernate, Runtime Optionally Perform Mappings? Hibernate Mappings会自动创建附加列-Spring - Hibernate Mappings results in creating addtional columns automatically - Spring Hibernate 不会在 @OneToMany 实体映射中自动创建反向映射 - Hibernate not creating back mappings automatically in @OneToMany entity mapping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM