Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: hibernate.hbm2ddl.auto=update show generated sql

I wish to pass to Hibernate's SessionFactory

hibernate.hbm2ddl.auto=update

and see in log file generated sql statements. Is it possible w/o java coding (know how to achieve the result with SchemaExport, but hope that hibernate has "in box" solution)

like image 483
FoxyBOA Avatar asked Mar 13 '10 08:03

FoxyBOA


People also ask

What is hibernate hbm2ddl auto update?

hbm2ddl. auto Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.

What hibernate will do if the value of hibernate hbm2ddl Auto is create '?

auto Create : If the value is CREATE then the hibernate first drops the existing tables data and structure, then creates new tables and executes the operations on the newly created tables.


1 Answers

You could setup logging to System.out using

  • SessionFactory sf = new Configuration().setProperty("hibernate.show_sql", "true")

  • or log4j

    log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER   
    log4j.additivity.org.hibernate.SQL=false
    

EDIT: This maybe also helpful Hibernate sql logging with values

like image 134
stacker Avatar answered Nov 07 '22 23:11

stacker