[英]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.