---
title: "基于hibernate的das实现研究(3)"
author: "hongsoft"
date: "2006-12-28T21:04:00Z"
tags: []
slug: "hibernate-das-3"
draft: false
lastmod: "2006-12-28T21:04:00Z"
id: 287401
url: "https://hongsoft.iteye.com/blog/287401"
---

一般如果有人反对使用Hibernate，他的第一个理由就是Hibernate的性能问题。

我们测试的结果是Hibernate的时间消耗基本是jdbc的1.4倍。其中我认为比较大的一个问题就是cache的内存占用，最基本的，hibernate会在session-level的cache中保存所有新insert的object，而其实这些新插入的object在一般的web系统中是不会马上用到的。

 hibernate3.2为了解决这个问题，新加入了StatelessSession实现，StatelessSession提供的是Command-Oriented API，它取出的对象是全部detached的。它与cache无关，与dirty-checking无关，与association无关，与Collection无关，与interceptor无关。

它的insert/update/delete/select可以理解为一般的JDBC操作。reference中的example如下：

StatelessSession session = sessionFactory.openStatelessSession();  
Transaction tx = session.beginTransaction();  
    
ScrollableResults customers = session.getNamedQuery("GetCustomers")  
    .scroll(ScrollMode.FORWARD\_ONLY);  
while ( customers.next() ) {  
    Customer customer = (Customer) customers.get(0);  
    customer.updateStuff(...);  
    session.update(customer);  
}  
    
tx.commit();  
session.close();

 

可惜的是，GavinKing没有做SDO模式的StatelessSession 。