Hibernate - slow execution of named query
I'm having issues with some of the named queries returning large number of
records (~30000). For example one of the queries looks like this:
SELECT d.name FROM AppUsersEntity d, AppGroupsEntity g WHERE
d.active=:active and g.groupname=:groupname order by upper(d.name) asc
The query is executed like this:
userNames=manager.createNamedQuery("myQueryName")
.setParameter("groupname",groupname)
.setParameter("active",1)
.getResultList();
If I execute the same query directly from MSSQL, the execution takes only
a few miliseconds.
Here is the result of profiling done during the execution. The execution
time of the two statements below is around 12.000.000:
declare @p1 int set @p1=8 exec sp_prepexec @p1 output,N'@P0
varchar(8000)',N'select appuser0_.USERNAME as col_0_0_ from APPUSERS
appuser0_, APPGROUPS groupsenti1_ where appuser0_.ACTIVE=1 and
groupsenti1_.GROUPNAME=@P0 order by upper(appuser0_.USERNAME) asc
','MYGROUP' select @p1
select appuser0_.USERNAME as col_0_0_ from APPUSERS appuser0_, APPGROUPS
groupsenti1_ where appuser0_.ACTIVE=1 and groupsenti1_.GROUPNAME=@P0 order
by upper(appuser0_.USERNAME) asc
Please provide any idea that could help me fix this.
Thank you,
No comments:
Post a Comment