I am getting this error when trying to filter a collection (getAssessments) for an object (PoClassMeasurement) I've just retrieved. Am I doing the filter incorrectly? or what.
I hope I've provide the information below correctly. I appreciate the template as to what to provide. At first, it seemed a little irritating. But on second though it probably ensures a better chance of getting good help and the process might have actually caused me to find my own problem. Keep up the great work.
Thank you - Richard
Hibernate version: 2.1.4
Mapping documents: (I cut out properties that were not relevant to keep this reasonable to read).
<hibernate-mapping> <class name="com.ltoj.persistence.base.PoClassMeasurement" table="PoClassMeasurement" proxy="com.ltoj.persistence.base.PoClassMeasurement" dynamic-update="false" dynamic-insert="false" >
<jcs-cache usage="read-write" />
<id name="id" column="id" type="long" unsaved-value="null" > <generator class="native"> </generator> </id>
<version name="version" type="int" column="version" />
<set name="assessments" table="PoAssessment" lazy="true" inverse="false" cascade="none" sort="unsorted" order-by="assessmentDate" >
<key column="classMeasurement" />
<one-to-many class="com.ltoj.persistence.base.PoAssessment" /> </set>
</class> </hibernate-mapping>
<hibernate-mapping> <class name="com.ltoj.persistence.base.PoAssessment" table="PoAssessment" proxy="com.ltoj.persistence.base.PoAssessment" dynamic-update="false" dynamic-insert="false" >
<jcs-cache usage="read-write" />
<id name="id" column="id" type="long" unsaved-value="null" > <generator class="native"> </generator> </id>
<version name="version" type="int" column="version" />
<many-to-one name="classMeasurement" class="com.ltoj.persistence.base.PoClassMeasurement" cascade="none" outer-join="false" update="true" insert="true" > <column name="classMeasurement" unique-key="userkey" /> </many-to-one>
<property name="assessmentDate" type="java.sql.Date" update="true" insert="true" > <column name="assessmentDate" unique-key="userkey" /> </property>
</class> </hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
// THE reported exception (in log messages below) occurs in line 221 of this method (I've annotated the method to show which line):
/** * Build sorted list of assessments. */ private List buildSortedAssessments(PoClassMeasurement classMeasurement, boolean assessmentSortAscending, HttpServletRequest request, ActionMessages errors) { UtilTimerStack.push("ClassGrid.buildSortedAssessments"); if (log.isDebugEnabled()) log.debug("buildSortedAssessments - entry."); List sortedAssessments = null;
if (classMeasurement.getAssessments() == null || classMeasurement.getAssessments().size() < 1) { if (log.isDebugEnabled()) log.debug("buildSortedAssessments - measurement has no assessments, cannot sort"); return sortedAssessments; } // if (log.isDebugEnabled()) log.debug("buildSortedAssessments - Retrieving assessments for measurement."); boolean someError = false; Collection sortedAssessmentsCol = null; // Filter classMeas's assessments by date (asc or desc). Session ses = ServiceLocator.getUserTransaction().getSession(); try {
if ( assessmentSortAscending ) { sortedAssessmentsCol = ses.filter(classMeasurement.getAssessments(), "order by this.assessmentDate"); } else { // LINE 221 FROM THE STACK TRACE IS THE FOLLOWING LINE: sortedAssessmentsCol = ses.filter(classMeasurement.getAssessments(), "order by this.assessmentDate desc"); } } catch (HibernateException he) { he.printStackTrace(); log.error("buildSortedAssessments - Exception occurred sorting assessments for class measurement id="+classMeasurement.getId()); log.debug("buildSortedAssessments - Exception stacktrace: '"+he.getStackTrace().toString()); return sortedAssessments; }
sortedAssessments = new ArrayList(sortedAssessmentsCol); classMeasurement.setSortedAssessments( sortedAssessments );
if (log.isDebugEnabled()) log.debug("buildSortedAssessments - exit."); UtilTimerStack.pop("ClassGrid.buildSortedAssessments"); return sortedAssessments; }
// The following Session create and close methods are called from Servlet Filter
public static final ThreadLocal userTransaction = new ThreadLocal(); private static SessionFactory sf = null; private static ServiceLocator me; static { try { me = new ServiceLocator(); } catch (Exception e) { log.fatal("Error occurred initializing ServiceLocator"); e.printStackTrace(); } } ... public static UserTransaction createUserTransaction(PoUser loggedOnUser, String remoteHost) throws HibernateException, SQLException, java.net.UnknownHostException { PoUser u = null; Long userObjectId = null; Session s = null; Transaction t = null; String userHost = null; UserTransaction userTx = null;
s = sf.openSession(ai); ... }
public static void closeSession() throws HibernateException, JDBCException { UserTransaction userTx = (UserTransaction) userTransaction.get(); try { if (userTx.isRequestRollback()) { try { userTx.getTransaction().rollback(); } catch (Exception e) { try { userTx.getSession().close(); } catch (Exception oe) { log.fatal("Exception rollingback Hibernate transaction, subsequent exception: " + oe.getLocalizedMessage()+" / "+Thread.currentThread().getName()); } userTx.setTransaction(null); userTx.setSession(null); throw new RuntimeException("Application logic requested cancel of all updates - updates were NOT able to be cancelled successfully. Please inspect data."); } } else { try { userTx.getTransaction().commit(); } } catch (HibernateException he) { try { userTx.getSession().close(); } catch (Exception oe) { } if ( userTx.getTransaction() != null || userTx.getSession() != null ) { try { userTx.getSession().close(); } catch (Exception e) { } return; }
Full stack trace of any exception that occurs: 2004-08-30 12:50:09 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception java.util.ConcurrentModificationException at org.apache.commons.collections.SequencedHashMap$OrderedIterator.next(Unknown Source) at net.sf.hibernate.util.IdentityMap.entryList(IdentityMap.java(Compiled Code)) at net.sf.hibernate.util.IdentityMap.entries(IdentityMap.java(Inlined Compiled Code)) at net.sf.hibernate.impl.SessionImpl.preFlushCollections(SessionImpl.java(Inlined Compiled Code)) at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java(Compiled Code)) at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java(Compiled Code)) at net.sf.hibernate.impl.SessionImpl.getFilterTranslator(SessionImpl.java:3453) at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3509) at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3404) at com.ltoj.webapp.util.ClassGrid.buildSortedAssessments(ClassGrid.java:221) at com.ltoj.webapp.util.ClassGrid.<init>(ClassGrid.java:129) at com.ltoj.webapp.action.GridAction.refreshGrid(GridAction.java:547) at com.ltoj.webapp.action.GridAction.refresh(GridAction.java:298) at com.ltoj.webapp.action.GridAction.unspecified(GridAction.java:161) at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:258) at com.ltoj.webapp.action.BaseAction.execute(BaseAction.java:162) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1158) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397) at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code)) at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code)) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code)) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code)) at com.atlassian.util.profiling.filters.ProfilingFilter.doFilter(ProfilingFilter.java:132) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code)) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code)) at com.ltoj.webapp.filter.BreadCrumbFilter.doFilter(BreadCrumbFilter.java(Compiled Code)) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code)) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code)) at com.ltoj.webapp.filter.ActionFilter.doFilter(ActionFilter.java:389) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code)) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled Code)) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java(Compiled Code)) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code)) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code)) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java(Compiled Code)) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java(Compiled Code)) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code)) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java(Compiled Code)) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code)) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code)) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java(Compiled Code)) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code)) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java(Compiled Code)) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code)) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code)) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java(Compiled Code)) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java(Compiled Code)) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java(Compiled Code)) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java(Compiled Code)) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java(Compiled Code)) at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java(Compiled Code)) at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java(Compiled Code)) at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java(Compiled Code)) at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:650) at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:829) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:688) at java.lang.Thread.run(Thread.java:568)
Name and version of the database you are using: MySQL 4.0.18 on SuSE Linux Enterprise Server 8 for AMD 64
Debug level Hibernate log excerpt: This is a production problem I am having trouble reproducing so far.
|