今天向一位同學請教了如何在控制臺輸出 Hibernate 工作過程中生成的 SQL, 非常簡單, 不過還是十分感謝分享. 畢竟先知者為師.
簡單說就是如下所示:
<!-- Output sql of hibernate -->
<property name="hibernate.show_sql">true</property>
這時控制臺會顯示如下的信息:
Hibernate: select users_seq.nextval from dual
Hibernate: insert into users (username, password, age, sex, id) values (?, ?, ?, ?, ?)
可以看到 Hibernate 是用 PreparedStatement 工作的, 跟我以前做的 BeanJDBC Persistence 研究項目用的思路一致.
一份完整的配置文件:
<?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
冬天出走的豬 閱讀(541)
評論(0) 編輯 收藏 所屬分類:
Database