今天向一位同學(xué)請(qǐng)教了如何在控制臺(tái)輸出 Hibernate 工作過(guò)程中生成的 SQL, 非常簡(jiǎn)單, 不過(guò)還是十分感謝分享. 畢竟先知者為師.
簡(jiǎn)單說(shuō)就是如下所示:
<!-- Output sql of hibernate -->
<property name="hibernate.show_sql">true</property>
這時(shí)控制臺(tái)會(huì)顯示如下的信息:
Hibernate: select users_seq.nextval from dual
Hibernate: insert into users (username, password, age, sex, id) values (?, ?, ?, ?, ?)
可以看到 Hibernate 是用 PreparedStatement 工作的, 跟我以前做的 BeanJDBC Persistence 研究項(xiàng)目用的思路一致.
一份完整的配置文件:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- localhost mysql config -->
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost/test
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">
com.mysql.jdbc.Driver
</property>
<property name="connection.password"></property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- Output sql of hibernate -->
<property name="hibernate.show_sql">true</property>
<mapping resource="entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
posted on 2007-08-13 10:46
冬天出走的豬 閱讀(540)
評(píng)論(0) 編輯 收藏 所屬分類:
Database