Getting DDL before updating a Spring application hibernation scheme

Annex Spring -Hibernate, hibernate.show_sql=truefile properties log4j enough to display the sleep-generated query. But what should we do if we need the actual sql query. (For a production environment, I need to observe and verify the request before updating the schema).

What I'm going to do, after creating the first schema in production (by sleeping itself), I don't want hibernate to update the schema (DDL). I want to capture change, update (DDL) requests and after checking I would like to run these scripts manually in the database. Is there any way to do this?

0
source share
2 answers

Hibernate has a built-in function to enable logging of all generated SQL statements to the console. You can enable it by adding a property show_sqlto the Hibernate configuration file hibernate.cfg.xml. This feature is good for troubleshooting basic issues and for seeing what Hibernate is doing.

hibernate.cfg.xml

show_sql

Enable logging of all generated SQL statements to the console

<property name="show_sql">true</property>

format_sql

Format the generated SQL statement to make it more readable, but takes up more screen space.

<property name="format_sql">true</property>

use_sql_comments

Hibernate will post comments inside all generated SQL statements to hint that the generated SQL is trying to do

<property name="use_sql_comments">true</property>

log4j.properties

log4j.logger.org.hibernate=INFO, hb
log4j.logger.org.hibernate.SQL=DEBUG ## is equivalent to hibernate.show_sql=true
log4j.logger.org.hibernate.type=TRACE ## allows you to see the binding parameters
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug

log4j.appender.hb=org.apache.log4j.ConsoleAppender
log4j.appender.hb.layout=org.apache.log4j.PatternLayout
log4j.appender.hb.layout.ConversionPattern=HibernateLog --> %d{HH:mm:ss} %-5p %c - %m%n
log4j.appender.hb.Threshold=TRACE
log4j.logger.org.hibernate.tool.hbm2ddl=debug

To print the binding parameters, add the following to the log4j.properties file:

log4j.logger.net.sf.hibernate.type=debug
0

log4j.properties

SQL- log4j.logger.org.hibernate.SQL=debug

JDBC, log4j.logger.org.hibernate.type=trace

show sql hibernate .

<property name="show_sql">true</property>

. post

0

All Articles