[Building Sakai] weird performance problem in hibernate

Charles Hedrick hedrick at rutgers.edu
Wed Feb 19 11:33:41 PST 2014


Can anyone make suggestions with this?

In Lessons, when exporting and copying, I sometimes need to find all items on any page of the site. I use code like this:

        public List<SimplePageItem> findTextItemsInSite(String siteId) {
            Object [] fields = new Object[1];
            fields[0] = siteId;
            List<String> ids = sqlService.dbRead("select b.id from lesson_builder_pages a,lesson_builder_items b where a.siteId = ? and a.pageId = b.pa\
geId and b.type = 5", fields, null);

            List<SimplePageItem> result = new ArrayList<SimplePageItem>();

            if (result != null) {
                for (String id: ids) {
                    SimplePageItem i = findItem(new Long(id));
                    result.add(i);
                }
            }
            return result;
        }


I realie that this isn’t optimal, but it’s also not done very often, so it shouldn’t be an issue. But I recently found a thread that was doing an export, where the equivalent code looking for all text items took hours and didn’t show any sign of ending. I include a stack trace at the end of this message.

What I’ve done for that case is avoid hibernate entirely. I just need a couple of fields from the items, so the query returns them and I generate items myself that just have those fields filled in. But I have methods like this returning other sets of items. In principle I can do the same thing for all of them, but do I have to? Anyone have idea idea why this is taking so long? It’s hard to believe that this would ever result in more than a few hundred items. Is there some pitfall I don’t know about in fetching that many items and putting them in a list?


java.lang.Class.getInterfaces(Native Method)
org.hibernate.intercept.FieldInterceptionHelper.extractFieldInterceptor(FieldInterceptionHelper.java:45)
org.hibernate.intercept.FieldInterceptionHelper.clearDirty(FieldInterceptionHelper.java:81)
org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:209)
org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:127)
org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:970)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1563)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1065)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1055)
org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1048)
org.sakaiproject.lessonbuildertool.model.SimplePageToolDaoImpl.findItem(SimplePageToolDaoImpl.java:270)
org.sakaiproject.lessonbuildertool.model.SimplePageToolDaoImpl.findTextItemsInSite(SimplePageToolDaoImpl.java:230)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
com.sun.proxy.$Proxy62.findTextItemsInSite(Unknown Source)
org.sakaiproject.lessonbuildertool.ccexport.CCExport.outputAllTexts(CCExport.java:607)
org.sakaiproject.lessonbuildertool.ccexport.CCExport.download(CCExport.java:1030)
org.sakaiproject.lessonbuildertool.ccexport.CCExport.doExport(CCExport.java:214)




More information about the sakai-dev mailing list