Hi all,
I am busy developing the user and role admin use-cases for my application and have come across a conundrum that I am not quite sure how to solve.
I am trying to update roles available to users of the system. The conundrum comes in when I try to update a Role that the current user is a part of. If this happens I get a org.hibernate.NonUniqueObjectException which makes sense because there is one instance attached to the current user which is retrieved every session and there is one instance which I am trying to update.
Does anybody know how I might go about updating any role without causing this issue? I am building a web application and am using the session per request approach suggested in "Hibernate In Action"
I understand that theoretically the two roles will be out of synch for the rest of the request but I am willing to let that be the case if it is possible.
Thanks
Tom
p.s. The reason the user is retrieved each time is to check for authorization so it is required. I also place the user in the session because there are individualized settings which are used on some of the web pages.
Hibernate version:
Hibernate in JBoss 4.0.2 (2.1.7 I think)
Full stack trace of any exception that occurs:
10:22:34,589 WARN [RequestProcessor] Unhandled Exception thrown: class org.hibernate.NonUniqueObjectException
10:22:34,589 INFO [STDOUT] javax.servlet.ServletException: a different object with the same identifier value was alread
y associated with the session: [com.camp.common.config.user.Role#3]
10:22:34,589 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.processException(Ljavax.servlet.http.HttpSe
rvletRequest;Ljavax.servlet.http.HttpServletResponse;Ljava.lang.Exception;Lorg.apache.struts.action.ActionForm;Lorg.apac
he.struts.action.ActionMapping;)Lorg.apache.struts.action.ActionForward;(RequestProcessor.java:545)
10:22:34,589 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.processActionPerform(Ljavax.servlet.http.Ht
tpServletRequest;Ljavax.servlet.http.HttpServletResponse;Lorg.apache.struts.action.Action;Lorg.apache.struts.action.Acti
onForm;Lorg.apache.struts.action.ActionMapping;)Lorg.apache.struts.action.ActionForward;(RequestProcessor.java:486)
10:22:34,589 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.process(Ljavax.servlet.http.HttpServletRequ
est;Ljavax.servlet.http.HttpServletResponse;)V(RequestProcessor.java:274)
10:22:34,589 INFO [STDOUT] at org.apache.struts.action.ActionServlet.process(Ljavax.servlet.http.HttpServletRequest
;Ljavax.servlet.http.HttpServletResponse;)V(ActionServlet.java:1482)
10:22:34,589 INFO [STDOUT] at org.apache.struts.action.ActionServlet.doPost(Ljavax.servlet.http.HttpServletRequest;
Ljavax.servlet.http.HttpServletResponse;)V(ActionServlet.java:525)
10:22:34,589 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(Ljavax.servlet.http.HttpServletRequest;Ljavax.
servlet.http.HttpServletResponse;)V(HttpServlet.java:717)
10:22:34,589 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(Ljavax.servlet.ServletRequest;Ljavax.servlet.S
ervletResponse;)V(HttpServlet.java:810)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax.servlet.Servl
etRequest;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:252)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax.servlet.ServletReques
t;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:173)
10:22:34,589 INFO [STDOUT] at org.securityfilter.filter.SecurityFilter.doFilter(Ljavax.servlet.ServletRequest;Ljava
x.servlet.ServletResponse;Ljavax.servlet.FilterChain;)V(SecurityFilter.java:188)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax.servlet.Servl
etRequest;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:202)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax.servlet.ServletReques
t;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:173)
10:22:34,589 INFO [STDOUT] at com.camp.common.utilities.HibernateFilter.doFilter(Ljavax.servlet.ServletRequest;Ljav
ax.servlet.ServletResponse;Ljavax.servlet.FilterChain;)V(Unknown Source)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax.servlet.Servl
etRequest;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:202)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax.servlet.ServletReques
t;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:173)
10:22:34,589 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(Ljavax.servlet.ServletRequest
;Ljavax.servlet.ServletResponse;Ljavax.servlet.FilterChain;)V(ReplyHeaderFilter.java:81)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Ljavax.servlet.Servl
etRequest;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:202)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(Ljavax.servlet.ServletReques
t;Ljavax.servlet.ServletResponse;)V(ApplicationFilterChain.java:173)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(Lorg.apache.catalina.connector.R
equest;Lorg.apache.catalina.connector.Response;)V(StandardWrapperValve.java:213)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(Lorg.apache.catalina.connector.R
equest;Lorg.apache.catalina.connector.Response;)V(StandardContextValve.java:178)
10:22:34,589 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(Lorg.apache.catalina.connec
tor.Request;Lorg.apache.catalina.connector.Response;)V(CustomPrincipalValve.java:39)
10:22:34,589 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Lorg.apache.catalina.co
nnector.Request;Lorg.apache.catalina.connector.Response;)V(SecurityAssociationValve.java:153)
10:22:34,589 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(Lorg.apache.catalina.connector.
Request;Lorg.apache.catalina.connector.Response;)V(JaccContextValve.java:59)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(Lorg.apache.catalina.connector.Requ
est;Lorg.apache.catalina.connector.Response;)V(StandardHostValve.java:126)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(Lorg.apache.catalina.connector.Req
uest;Lorg.apache.catalina.connector.Response;)V(ErrorReportValve.java:105)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(Lorg.apache.catalina.connector.Re
quest;Lorg.apache.catalina.connector.Response;)V(StandardEngineValve.java:107)
10:22:34,589 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(Lorg.apache.coyote.Request;Lorg.a
pache.coyote.Response;)V(CoyoteAdapter.java:148)
10:22:34,589 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Ljava.io.InputStream;Ljava.io.Output
Stream;)V(Http11Processor.java:856)
10:22:34,589 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Lor
g.apache.tomcat.util.net.TcpConnection;[Ljava.lang.Object;)V(Http11Protocol.java:744)
10:22:34,589 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(Ljava.net.Socket;Lorg.apache
.tomcat.util.net.TcpConnection;[Ljava.lang.Object;)V(PoolTcpEndpoint.java:527)
10:22:34,589 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run()V(MasterSlaveWorkerThread.jav
a:112)
10:22:34,589 INFO [STDOUT] at java.lang.Thread.run()V(Unknown Source)
Name and version of the database you are using:
Postgres 8.0
|