摘要: 1.采用getCurrentSession()创建的Session会绑定到当前的线程中去;而采用OpenSession()则不会。2.采用getCurrentSession()创建的Session在commit或rollback后会自动关闭;采用OpenSession()必须手动session.close()关闭。3.采用getCurrentSession()需要在Hibernate.cfg.xml配置文件中加入如下配置:未绑定当前线程会出现异常:org.hibernate.HibernateException: No Hibernate Session bound to thread* 如果 阅读全文
posted @ 2013-06-20 16:45 Kent_fighting 阅读(251) 评论(0) 推荐(0) 编辑
摘要: Lucene是一个高性能的java全文检索工具包,它使用的是倒排文件索引结构。使用like "%keyword%"时,数据库索引是不起作用的,Lucene检索过程就是把模糊查询变成多个可以利用索引的精确查询的逻辑组合的过程。该结构及相应的生成算法如下:0)设有两篇文章1和2文章1的内容为:Tom lives in Guangzhou,I live in Guangzhou too.文章2的内容为:He once lived in Shanghai.1)由于lucene是基于关键词索引和查询的,首先我们要取得这两篇文章的关键词,通常我们需要如下处理措施a.我们现在有的是文章内 阅读全文
posted @ 2013-06-20 16:42 Kent_fighting 阅读(569) 评论(0) 推荐(0) 编辑
摘要: Spring对Hibernate的集成提供了很好的支持,Spring提供了对sessionfactory的初始化,用户不用再关心session的open,close,同时,Spring还提供了灵活的事务声明.本文通过实例简单讲述如何在Spring中集成Hibernate.1,将hibernate的配置加入到Spring的配置中(对datasource和sessionfactory进行配置):[html] view plaincopyprint?com/test/spring/hibernate/Hbtest.hbm.xmlhibernate.dialect=org.hibernate.dial 阅读全文
posted @ 2013-06-20 16:38 Kent_fighting 阅读(302) 评论(0) 推荐(0) 编辑
摘要: 异常:org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined (sessionFactory没有定义)在web.xml中配置OpenSessionInViewFilter时应该指定SessionFactory的名字,配置如下:HibernateOpenSessionorg.springframework.orm.hibernate3.support.OpenSessionInViewFiltersessionFactory 阅读全文
posted @ 2013-06-20 16:35 Kent_fighting 阅读(1127) 评论(0) 推荐(0) 编辑
摘要: public boolean checkUserExistsWithName(String username) {SessionFactory sf = HibernateUtil.getSessionFactory();Session s = sf.getCurrentSession();s.beginTransaction();long count = (Long)s.createQuery("select count(*) from User u where u.username=:username").setString("username",u 阅读全文
posted @ 2013-06-20 16:29 Kent_fighting 阅读(566) 评论(0) 推荐(0) 编辑