Poor performance using Hibernate Criteria API

我与影子孤独终老i 提交于 2019-12-10 17:48:02

问题


I have a Java application using Hibernate to communicate with a MsSQL 2005 server, the driver is net.sourceforge.jtds 1.2.4.

Things are working but the performance is horrible, I suspect the index isn't used for the queries passed to it, since the response times are proportional to the number of entries in the table.


I have written a small test application that use the same driver (jtds) but doesn't use Hibernate and I have been able to reproduce the poor performance (or so I believe). When I use a prepared statements I see the same poor performance as using Hibernate (response times of ~1s), but when I don't the performance is great (~10ms).

I am able to get the same good performance using the Hibernate executeSql method instead of the Criteria interface, but I want to avoid this since I want the code to stay modular and also the results are not converted to my entity class.

Is there some way to have the good performance with Hibernate, while still using a backend-agnostic way of making queries and having the results converted to entity class objects?


回答1:


Have you tried the proprietary driver from Microsoft? You can download it here. And an overview of the supported configurations is shown here. It might give you better performance.

A related post on SO might also be of help to you: how to configure hibernate config file for sql server



来源:https://stackoverflow.com/questions/8412717/poor-performance-using-hibernate-criteria-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!