Skip to main content

Posts

Showing posts from January, 2013

Hibernate SchemaExport tool for Automatic schema generation

Hibernate provides various utilities for developer in which SchemaExport is the one of those utilities that generates SQL queries representing the schema including referential integrity, keys, relationship for the entities and collations. you can use these generated schema to populate the tables structure in database. Dialect must be specified there before creating schema so that this tool can generate the SQL queries aligned with that database system. I am assuming that you have already declared entities in hibernate.cfg.xml file, Here is the source code for doing so,                  Configuration   configuration  =   new   Configuration () . configure () ;          SessionFactory  sessionFactory  =  configuration. buildSessionFactory () ;                  SchemaExport  schema  =   new   SchemaExport ( configuration ) ;         schema. setOutputFile ( "F:/schema.sql" ) ;         schema. create ( true ,  false ) ;