java - Trying to optmize a Hibernate Query with read only -
java - Trying to optmize a Hibernate Query with read only -
i'm trying optmize query taking little longer expected. query returns 11000 entities, since bit complicated , have nested entities it's slow. since i'm not going modify entities, tried setting query/session read-only, hasn't helped, still takes long, maybe i'm doing wrong. below simplified code, sorry it's little messy:
@entity @namedqueries(value = {@namedquery(name = "demand.all", query = "select d demand d")}) public class demand { private long id; private partition division; private client client; private product product; private string code; ... } @transactional(readonly=true) public list<demand> getall() { sessionimpl sessionimpl = ((sessionimpl)em.getdelegate()); session session = sessionimpl.getsessionfactory().opensession(); transaction tx = session.begintransaction(); seek { sessionimpl.connection().setreadonly(true); query query = session.getnamedquery("demand.all"); list<demand> resultlist = query.setreadonly(true).setcacheable(false).setflushmode(flushmode.manual).list(); sessionimpl.connection().setreadonly(false); tx.commit(); } catch(exception e) { resultlist = null; } session.close(); homecoming resultlist; }
i read making query read-only not enough, tried setting connection , transaction read-only too, i'm not sure if it's necessary. anyways, doing wrong? other way there optimize query?
one way of doing faster fetching objects in lazy way or depending on necessary , not. maybe need show 5 columns in table, instead of every single object in hierarchy, create dto them. if need more info on 1 of them.. lets user clicks on row, bring whole object hierarchy of it..
it may not apply in case, 1 way of efficiently getting data.
java hibernate
Comments
Post a Comment