Wednesday, September 09, 2009

Hibernate Schema tools

The hbm2ddl.auto column indicates the values for the hbm2ddl.auto property in the hibernate configuration file

The Purpose column indicates what is the impact of using the specified hbm2ddl.auto value

The Class Name column indicates how to achieve the “purpose” programmatically.

 

hbm2ddl.auto option

Purpose

Class name

create or create-drop or

create – to drop the schema and create it whenever SessionFactory is built

create-drop – to drop the schema when SessionFactory is closed.

 

SchemaExport

e.g.

SchemaExport ex = new SchemaExport( new Configuration().configure() );

Ex.create(false, true);

// false – don’t print sql to stdout

// true – Execute ddl immediately on database

Update

Update – Read the schema through JDBC driver (not reliable) and make schema changes to fit the schema to mappings

SchemaUpdate

e.g.

SchemaUpdate su =

New SchemaUpdate(new Configuration().configure() );

Su.execute(false); // don’t print ddl on stdout

Validate

Validator – compare mapping with metadata and throw exception if they do not match.

SchemaValidator

e.g.

new SchemaValidator(new Configuration().configure()).validate()

 

No comments: