AdaroMu
AdaroMu

Reputation: 166

How to automatically map POJOs to database to create tables using NetBeans

I have wrote some POJOs in NetBeans, and want to map these entities automatically to an empty database, to be tables.

I have read the netbeans official tutorial https://netbeans.org/kb/docs/java/hibernate-java-se.html#06a

But using Hibernate Mapping File as the document says can not choose the Database Table value, compare to the pic enter image description here

(https://netbeans.org/images_www/articles/70/java/hibernate-j2se/mapping-wizard.png,

The actor value will not show since my database is empty.

So what should I do if I followed the tutorial, or is there any other method to automatically create tables by POJO in NetBeans?

Upvotes: 1

Views: 8899

Answers (2)

Masudul
Masudul

Reputation: 21961

Use SchemaExport.export. Run following code in main() method:

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

Upvotes: 0

Vimal Bera
Vimal Bera

Reputation: 10497

There is one property hibernate.hbm2ddl.auto in hibernate which create tables as per your pojo structure.

Refer this doc.

Upvotes: 1

Related Questions