随笔 - 4  文章 - 10  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(1)

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

今天向一位同学请教了如何在控制台输出 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 冬天出走的猪 阅读(527) 评论(0)  编辑  收藏 所属分类: Database

只有注册用户登录后才能发表评论。


网站导航: