Hibernate中的show_sql和Spring中的hibernate.show_sql的區別

Hibernate中的show_sql和Spring中的hibernate.show_sql的區別

Hibernate配置文件的屬性是show_sql
而Spring配置文件中的屬性是hibernate.show_sql

其實Hiberante中用的也是hibernate.show_sql,
只不過hibernate這段字符串是在org.hibernate.cfg.Configuration類的addProperties()方法中自動加上的:

  private void addProperties(Element parent) {
        Iterator iter = parent.elementIterator( "property" );
        while ( iter.hasNext() ) {
            Element node = (Element) iter.next();
            String name = node.attributeValue( "name" );
            String value = node.getText().trim();
            log.debug( name + "=" + value );
            properties.setProperty( name, value );
            if ( !name.startsWith( "hibernate" ) ) {     //在這裏加個hiberate字符串
                properties.setProperty( "hibernate." + name, value );
            }
        }
        Environment.verifyProperties( properties );
    }

例如:

Hibernate配置文件:

<property name="show_sql">true</property>
<property name="connection.autocommit">false</property> <!-- 在Hibernate中默認爲false -->

Spring配置文件:

<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.autocommit">false</prop>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章