500 after trying to delete roles

EDIT: OpenMRS WAR 2.2.0

I’m trying to delete a lot of the roles that came pre-loaded, and oftentimes after attempting it I get an error, and when trying to access http://10.0.0.41:8080/openmrs/admin/users/role.list I get the below output. Then, about 5 minutes later all seems well.

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Request processing failed; nested exception is org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.openmrs.Role#Organizational: Doctor]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.openmrs.Role#Organizational: Doctor]
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:60)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:73)
	org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:57)
	org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:109)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:107)
	org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:107)
	org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:107)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.openmrs.Role#Organizational: Doctor]
	org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:253)
	org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)
	org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:259)
	org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
	org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1106)
	org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1025)
	org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:716)
	org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:282)
	org.hibernate.collection.internal.PersistentSet.initializeFromCache(PersistentSet.java:145)
	org.hibernate.cache.spi.entry.CollectionCacheEntry.assemble(CollectionCacheEntry.java:75)
	org.hibernate.event.internal.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:160)
	org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:76)
	org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1933)
	org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:683)
	org.hibernate.engine.internal.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:894)
	org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:360)
	org.hibernate.loader.Loader.doList(Loader.java:2554)
	org.hibernate.loader.Loader.doList(Loader.java:2540)
	org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
	org.hibernate.loader.Loader.list(Loader.java:2365)
	org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
	org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
	org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
	org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
	org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
	org.openmrs.api.db.hibernate.HibernateUserDAO.getAllRoles(HibernateUserDAO.java:273)
	org.openmrs.api.impl.UserServiceImpl.getAllRoles(UserServiceImpl.java:275)
	sun.reflect.GeneratedMethodAccessor229.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:498)
	org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
	com.sun.proxy.$Proxy229.getAllRoles(Unknown Source)
	sun.reflect.GeneratedMethodAccessor229.invoke(Unknown Source)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:498)
	org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
	org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	org.springframework.cache.interceptor.CacheInterceptor$1.invoke(CacheInterceptor.java:52)
	org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:303)
	org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:122)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
	com.sun.proxy.$Proxy230.getAllRoles(Unknown Source)
	org.openmrs.web.controller.user.RoleListController.formBackingObject(RoleListController.java:152)
	org.springframework.web.servlet.mvc.AbstractFormController.getErrorsForNewForm(AbstractFormController.java:366)
	org.springframework.web.servlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:346)
	org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:288)
	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:146)
	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:60)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:73)
	org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:57)
	org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:109)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:107)
	org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:107)
	org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:107)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/8.5.43

EDIT: it just happened again. The other error I get, when trying to access http://10.0.0.41:8080/openmrs/admin/users/users.list, is

An error has occurred!
The following error happened somewhere on this page:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.openmrs.Role#Organizational: System Administrator] 

(The full error stack trace output is in the source of this page.)

I’m not clear where to find the full error stack trace output, “in the source of this page” doesn’t make sense to me.

This just happened again when trying to delete a simple role that I created. It was assigned to 2 users, but I removed it from those 2 users and tried to delete the role, and got the same 500 and now I’m locked out of managing users or roles. Hoping that restarting openMRS will resolve it faster.

Which environment are you working with ?

OpenMRS WAR 2.2.0

Clear all browser cache and History.

I’m 99% sure I did that each time this happened, but next time it happens I will make sure to do it and report back here.

I cleared the cache before and that didn’t help. This time I deleted all browser data and of course had to log back in to OpenMRS. However OpenMRS would not log me in, it failed silently several times until I restarted OpenMRS, then I could log in. So in short, clearing all browser data is not an acceptable solution to this common problem, but thank you for the suggestion.

Am glad you are able to login.

@jasonmfry can you create a ticket for this?

@dkayiwa yes but I don’t have an Atlassian account for OpenMRS, and the login page says

Not a member? To request an account, please contact your Jira administrators. Who should I ask to register me?

Kindly contact the Help Desk to request access to the wiki for edit/write access.