关于hibernate的两个问题

 1.SQL VS HQL
The Hibernate SQLQuery bypasses the Hibernate Session cache and queries ONLY against the
database. By the same token, HQL and the Hibernate Criteria queries check the Session cache
before executing the query. If there are objects that the HQL query may execute against
hibernate will flush the cache to the database.
Hibernate SQLQuery绕过Hibernate 会话的缓存,直接从数据库中查询;也就是说,HQL and
the Hibernate Criteria queries在执行前会先检查会话的缓存,如果缓存中存在该查询需要的
对象,hibernate会将它更新到数据库中去;

2.会话必须在一个线程使用,因为它不是线程安全的;
Sessions should be used by only one application thread at a time. This is a common concern in web applications, which are multithreaded by their very nature.

所以不要将在session1中取出来的东西,在session2中调用saveOrUpdate方法,会抛异常;

如果你必须要这样做的话,请使用save或者update方法,这样hibernate就不用通过判断来调用save或者update方法了。


http://i-proving.ca/space/Technologies/Hibernate/SQL+vs+HQL+with+the+Session+Cache
http://www.developer.com/open/article.php/10930_3559931_4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值