Tuesday 15 May 2012

Hibernate Built-in Tools


Hibernate supplies some built-in tools to create or alter database tables in underlying database software.
These tools are also useful to generate HB POJO class dynamically. They are

1.Scheema Export
2.Scheema Update
3.Code Generator(This Code is supplied in HB2.x  But not given in 3.x)
ØSchema Export tool always create new Table
ØSchema Update tool can create new table or can alter existing table by adding new columns
ØThese Two tools are very useful to create tables dynamically in new database software based on HB mapping file.
ØIf Programmer is not aware of SQL queries of new Database software then these tools are very useful.
ØWe can use schemaupdate,schemaexport tool along with hibernate application execution by passing special property in hibernate configuration file.
ØHibernate.hbm2ddl.auto possible values are
üCreate(uses schemaExport tool internally)
üUpdate(uses schemaUpdate tool internally)
üCreate-drop(uses schemExport tool internally)

In configuratio file
<property name=“hibernate.hbm2ddl.auto”>create</property>
Always creates new table in each execution
<property name=“hibernate.hbm2ddl.auto”>update</property>
Always creates new table/can use existing table/can alter existing table in each execution
<property name=“hibernate.hbm2ddl.auto”>create-drop</property>
This creates table dynamically in database software when sessionFactory object is created and drop all these tables when SessionFactory object is closed from the application
This will be helpful when we test the project.


For Sample Project




No comments:

Post a Comment