views:

184

answers:

1

Hi all, im developing a java swing app and i would use hibernate for persistance. Im totally new in jpa, hibernate and ORM in general.

Im follow this tutorial, its easy but the problem is the java class that descrive a table in db are made from the table with reverse enginering.

I want do the opposite process: i want make db table from the java class.

The question is, how can i do this with netbeans? There are some tutorial?

+1  A: 

Apparently, it is more usual to reverse engineer the database to generate the java class.

If you want to generate the database from the java class, you can generate a DDL for each hibernate object like this :

AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(User.class);
config.configure();
new SchemaExport(config).create(true, true);

With these parameters for the method create :
create(boolean script, boolean export)
script - print the DDL to the console
export - export the script to the database

zor