问题描述
ssh中spring的配置文件如何配置属性可以在控制台输出hibernate的sql语句? 谢谢<bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName"value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/abc"></property><property name="username" value="root"></property><property name="password" value="123"></property></bean><bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource"><ref bean="dataSource" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop></props></property><property name="mappingResources"><list><value>com/fff/dao/TZgxx.hbm.xml</value><value>com/fff/dao/TGrgzxx.hbm.xml</value></list></property></bean>
解决方案
<property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop></props></property>最好加上hibernate.format_sql格式化你的sql
解决方案二:
然后在applicationContext.xml中配:<property name="hibernateProperties"><props><prop key="hibernate.dialect">${hibernate.dialect}</prop><prop key="hibernate.show_sql">${hibernate.show_sql}</prop><prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop><prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop><prop key="hibernate.connection.release_mode">${hibernate.connection.release_mode}</prop></props></property>
解决方案三:
那个是配在hibernate.cfg.xml里面的, <session-factory><property name="hibernate.show_sql">true</property></session-factory>