如何使用NetBeans自动将POJOMap到数据库以创建表

fcipmucu  于 5个月前  发布在  其他
关注(0)|答案(2)|浏览(55)

我在NetBeans中编写了一些POJO,并希望将这些实体自动Map到一个空数据库中,成为表。
我看过netbeans官方教程https://netbeans.org/kb/docs/java/hibernate-java-se.html#06a
但使用Hibernate Mapping File作为文件说,不能选择Database Table值,比较图片

https://netbeans.org/images_www/articles/70/java/hibernate-j2se/mapping-wizard.png
actor值不会显示,因为我的数据库是空的。
那么,如果我按照教程操作,我应该怎么做呢?或者是否有其他方法可以在NetBeans中通过POJO自动创建表?

qni6mghb

qni6mghb1#

hibernate中有一个属性hibernate.hbm2ddl.auto,它可以根据你的pojo结构创建表。
参考这个doc。

siotufzp

siotufzp2#

使用SchemaExport.export。在main()方法中运行以下代码:

AnnotationConfiguration configuration = new AnnotationConfiguration();
 SchemaExport schemaExport = new SchemaExport(configuration);
 schemaExport.export(true, true, true, false);

字符串

相关问题