2014-09-24 2 views
0

최대 절전 모드에서 <property name="show_sql">true</property>으로 선언되었습니다. 이 link에서 stdout 문제를 읽었습니다. Stdout은 더 많은 메모리를 소비합니다. 그래서 show_sql 기능은 어떻게 작동할까요?. 왜냐하면 나는 서버 로그 stdout SQL 쿼리를 보았다.Hibernate show sql이 Stdout과 같습니다.

13:06:53,323 INFO [stdout] (http-/172.29.250.43:8080-7) Hibernate: select sampledata0_.idsample as idsample4_10_1_, sampledata0_.id as id1_9_1_, sampledata0_.id as id1_9_0_, sampledata0_.idsample as idsample4_9_0_, sampledata0_.sname as sname2_9_0_, sampledata0_.svalue as svalue3_9_0_ from sample_meta_data sampledata0_ where sampledata0_.idsample=? 
13:06:53,324 INFO [stdout] (http-/172.29.250.43:8080-7) Hibernate: select sampledata0_.idsample as idsample4_10_1_, sampledata0_.id as id1_9_1_, sampledata0_.id as id1_9_0_, sampledata0_.idsample as idsample4_9_0_, sampledata0_.sname as sname2_9_0_, sampledata0_.svalue as svalue3_9_0_ from sample_meta_data sampledata0_ where sampledata0_.idsample=? 

System.out.println을 내부적으로 최대 절전 모드로 가정합니다. 그럼 더 많은 기억을 소비할까요? format_sqlshow_sql은 내부적으로 어떻게 작동합니까?

답변

2

show_sql에 대한 trueformat_sql을 설정하면 더 많은 메모리를 소모하지 않습니다하지만 시간이 소요 그래서 그들은 콘솔에 SQL 문을 작성합니다. documentation에서

: 콘솔에 모든 SQL 문

쓰기. 이는 로그 카테고리 org.hibernate.SQL을 디버깅하도록 설정하는 것의 대안입니다.

사실 |

Hibernate는 내부적으로 사용 SQLStatementLogger class에서 SQL 문을 표시하는 방법 아래 사용 거짓

그래서 당신은 그 방법 이하로 사용하여 콘솔에 인쇄합니다 SQL 문을 최대 절전 모드 재산을 show_sqltrue에 설정할 때. 위의 방법에서

/** 
* Log a SQL statement string. 
* 
* @param statement The SQL statement. 
* @param style The requested formatting style. 
*/ 
public void logStatement(String statement, FormatStyle style) { 
    if (log.isDebugEnabled() || logToStdout) { 
     style = determineActualStyle(style); 
     statement = style.getFormatter().format(statement); 
    } 
    log.debug(statement); 
    if (logToStdout) { 
     System.out.println("Hibernate: " + statement); 
    } 
} 

format_sql는 다음 SQL 문을 포맷됩니다 true로 설정 또는 다른 형식의 스타일이 적용되지 않습니다.

이제 LOG 수준이 DEBUG으로 설정된 경우 SQL 문이 로그 파일에 기록됩니다. show_sql을 true로 설정하면 콘솔에 메시지를 인쇄합니다. 질문에 제공된 링크에서 언급했듯이 System.out.println을 사용하면 데이터를 로그 파일에 인쇄하는 것보다 시간이 많이 걸립니다.

일반적으로 응용 프로그램이 프로덕션 환경에있을 때 로그 파일에 메시지를 쓰는 데는 시간이 걸리기 때문에 로그 수준은 DEBUG으로 설정되지 않습니다.

+0

으로 설정해야합니다. "SQL.을 콘솔에 기록합니다." 그러나 쓰기에는 몇 밀리 초가 걸립니다. – ashokhein

+0

@ashokhein, 내 답변을 명확하게하기 위해 세부 사항을 업데이트했습니다. 확인하십시오. – Chaitanya

0

show_sql을 사용하면 명령문이 system.out에 인쇄됩니다. log4j 세트 파일에 명령문을 인쇄하려면 log4j.logger.org.hibernate.SQL의 레벨을 DEBUG

관련 문제