关于一个hibernate的问题

2 views
Skip to first unread message

lijue zhu

unread,
Dec 24, 2010, 3:16:00 AM12/24/10
to mave...@googlegroups.com
请教 一个低级问题。麻烦各位指条明路。

在hibernate 中我们不需要在代码 中显式的去连接数据库,关闭数据库。

而有些类似如下
conn = ConnectionUtils.getConnection();
            DatabaseMetaData dbm = conn.getMetaData();
的代码却显式的要连接数据库。关闭数据库。


那请问
1 。 hibernate 在哪里管理 连接关闭数据库是?是用sqlsession么?
2 。sqlsession 和这种显式的连接有何区别?

tomaer

unread,
Dec 25, 2010, 10:36:33 AM12/25/10
to mave...@googlegroups.com
hibernate 中有个sessionFactory来维护于Connection。说白了就是Session对象,Session对象中有个dataSource。
hibernate 会在session为创建的时候从sessionFactory中取得一个session,在事务提交之后销毁此对象。
Remark:openSession和getCurrentSession 有区别,从名字上看容易看出来。如果你还是看不出来 那么就google吧

2010/12/24 lijue zhu <liju...@gmail.com>
--
您收到此邮件是因为您订阅了 Google 网上论坛的“Maven中文”论坛。
要向此网上论坛发帖,请发送电子邮件至 mave...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 maven-zh+u...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/maven-zh?hl=zh-CN 访问此网上论坛。



--
Best Regards,
tomaer

Resilient Solutions Co. Ltd
Unit F, 25/F, Seabright Plaza, 9-23 Shell Street, North Point, HK.
Phone: (852) 3106 5273
Fax: (852) 3106 5227
Mobile: (755) 134 2432 6054
Email: i...@tomaer.com
WebSite:www.tomaer.com
Company Website: www.resilient-solutions.com
Reply all
Reply to author
Forward
0 new messages