LibrePlan / libreplan

LibrePlan - Open Web Planning
https://www.libreplan.dev
GNU Affero General Public License v3.0
289 stars 170 forks source link

Prevent adding the same profile to a user twice #1636

Closed kwoot closed 6 years ago

kwoot commented 12 years ago

(Original Bugzilla Bug ID: 1492)

Date: 2012-07-10 08:41:15 From: Jacobo Aragunde Perez \<jaragunde@igalia.com> To: Jacobo Aragunde Perez \<jaragunde@igalia.com> Version: master (1.3.x) Last updated: 2012-07-10 10:24:52


(Note: this issue was migrated automatically with bugzilla2github.py tool )

kwoot commented 6 years ago

Bugzilla Comment ID: 4172 Date: 2012-07-10 08:41:15 From: Jacobo Aragunde Perez \<jaragunde@igalia.com>

When you edit a user, you can add the same profile twice, but when you try to save the following exception appears:

org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:636) at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:789) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:663) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88) at org.libreplan.web.common.concurrentdetection.ConcurrentModificationHandling.whenConcurrentModification(ConcurrentModificationHandling.java:100) at sun.reflect.GeneratedMethodAccessor149.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:627) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:616) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:64) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:160) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy163.confirmSave(Unknown Source) at org.libreplan.web.users.UserCRUDController.save(UserCRUDController.java:165) at org.libreplan.web.common.BaseCRUDController.saveCommonActions(BaseCRUDController.java:229) at org.libreplan.web.common.BaseCRUDController.saveAndContinue(BaseCRUDController.java:243) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at bsh.Reflect.invokeMethod(Unknown Source) at bsh.Reflect.invokeObjectMethod(Unknown Source) at bsh.Name.invokeMethod(Unknown Source) at bsh.BSHMethodInvocation.eval(Unknown Source) at bsh.BSHPrimaryExpression.eval(Unknown Source) at bsh.BSHPrimaryExpression.eval(Unknown Source) at bsh.Interpreter.eval(Unknown Source) at bsh.Interpreter.eval(Unknown Source) at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:134) at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:341) at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:876) at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:180) at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138) at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.process0(EventProcessingThreadImpl.java:517) at org.zkoss.zk.ui.impl.EventProcessingThreadImpl.run(EventProcessingThreadImpl.java:444) Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:254) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:170) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655) ... 40 more Caused by: java.sql.BatchUpdateException: Batch entry 0 / insert collection row org.libreplan.business.users.entities.User.profiles / insert into user_profiles (user_id, profile_id) values ('50197', '44238') was aborted. Call getNextException to see the cause. at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2573) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1796) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2708) at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297) at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247) ... 48 more

kwoot commented 6 years ago

Bugzilla Comment ID: 4175 Date: 2012-07-10 09:14:57 From: Jacobo Aragunde Perez \<jaragunde@igalia.com>

No special checks are being done when the add button is pressed, when we press it we just add the Profile to the user, and we delegate the implementation of HashSet to control duplicated entries.

It looks like the HashSet is treating the same Profile as two different objects, probably because one comes from the DB when the User was instantiated and the other one comes from the Combobox, retrieved with ProfileDAO.list().

kwoot commented 6 years ago

Bugzilla Comment ID: 4178 Date: 2012-07-10 10:24:52 From: Jacobo Aragunde Perez \<jaragunde@igalia.com>

commit 0512d267f766cfb0a70d2b4508d935a9e85266d3 Author: Jacobo Aragunde Pérez jaragunde@igalia.com Date: Tue Jul 10 12:21:35 2012 +0200

Bug #1492: Check if the role had been added before.

FEA: ItEr76S04BugFixing