我使用SSH 在持久层进行查询,使用的是HibernteaTemplate().findByCriteria(DetachedCriteria.forClass(User.class))
进行查询 其中User.class是我在action里面传过来的 ,现在的问题是 我的User表中只有100多条信息 12列 每次打开网页查询的时间居然要15-30秒 才能打开页面数据,实在不太明白,所以来这里问问。希望能找到答案。
Hibernate 查询数据时,速度慢的异常。请大家帮忙看看。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
9条回答 默认 最新
- oxcow 2012-01-04 16:03关注
根据你提供的日志,这是你一次查询执行的所有SQL[code="SQL"]SELECT * FROM mastery.sale_pricing_record this_;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.doc_port docport0_ WHERE docport0_.id = ?;
SELECT * FROM mastery.doc_port docport0_ WHERE docport0_.id = ?;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.doc_port docport0_ WHERE docport0_.id = ?;
SELECT * FROM mastery.doc_port docport0_ WHERE docport0_.id = ?;
SELECT * FROM mastery.sale_customer this_;
SELECT * FROM mastery.doc_port this_;
SELECT * FROM mastery.doc_aircompany this_;
SELECT * FROM mastery.doc_shipcompany this_;[/code]其中我省略了你的表字段。
我们可以看下[code="sql"]SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;
SELECT * FROM mastery.sale_customer salecustom0_ WHERE salecustom0_.id = ?;[/code]
这个应该是你设置了一对多,但没有设置抓取数量导致的,针对一个id都需要一条sql,所以你需要设置下BatchSize。其他的就不说了。类似吧。注意个大小要合适,不能太大,因为其实他是吧上述四条SQL变成 id in (?,?,?...)的方式。至于你的意外发现,我没怎么遇到过,不过你的log4j也挺复杂的。你可以只把写文件关了,看是不是由写文件导致的。在一个就是吧不需要的打印的信息去掉,指保留SQL的。这是我的ssh项目log4j给你参考下,很简单的[quote]
log4j.rootLogger=info, stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %m [%l]%n#下面是为了查看hibernate映射,设置为debug。想要生效,
#只需要吧第一行的info改成debug就行
log4j.appender.org.springframework.orm.hibernate3 = debug
[/quote]对于log4j就只能提供这么多。你可以在自己搜搜。或者对你的log4j进行下测试。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Python爬取指定微博话题下的内容,保存为txt
- ¥15 vue2登录调用后端接口如何实现
- ¥65 永磁型步进电机PID算法
- ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥15 latex怎么处理论文引理引用参考文献
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?