Metadata Sharing Module
  1. Metadata Sharing Module
  2. META-264

Trying to import a MDS package with nested roles fails

    Details

    • Complexity:
      Low

      Description

      I tried to import a MDS package with roles and privileges, some of which duplicate existing roles and privileges in my system.

      I chose From Master mode, and it shows me almost everything being automatically assessed (see screenshot).

      There are two privileges I needed to assess manually (I changed the code that created these, so the incoming package has different descriptions), and I chose to use theirs.

      (I don't think these privileges are relevant to the error.)

      When I try to do the import I get this exception:

      INFO - LoggingAdvice.invoke(117) |2012-08-24 16:58:34,759| In method MetadataSharingService.saveImportedPackage. Arguments: ImportedPackage=org.openmrs.module.metadatasharing.ImportedPackage[3ad18fe2-13f1-49ea-8297-cb3f61184fcc], 
      INFO - LoggingAdvice.invoke(142) |2012-08-24 16:58:34,772| Exiting method saveImportedPackage
      ERROR - JDBCExceptionReporter.logExceptions(234) |2012-08-24 16:58:34,841| Duplicate entry 'API Privileges-Provider App' for key 'PRIMARY'
      ERROR - Task.log(123) |2012-08-24 16:58:34,880| Task failed
      org.openmrs.module.metadatasharing.task.TaskException: Task failed
      	at org.openmrs.module.metadatasharing.task.Task.log(Task.java:123)
      	at org.openmrs.module.metadatasharing.task.TaskEngine$RunnableTask.run(TaskEngine.java:127)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      	at java.lang.Thread.run(Thread.java:680)
      Caused by: org.openmrs.module.metadatasharing.task.TaskException: Task failed
      	... 4 more
      Caused by: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into role_role (parent_role, child_role) values (?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
      	at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:637)
      	at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
      	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
      	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
      	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
      	at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy161.executeTask(Unknown Source)
      	at org.openmrs.module.metadatasharing.task.TaskEngine$RunnableTask.run(TaskEngine.java:124)
      	... 3 more
      Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
      	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
      	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
      	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
      	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
      	at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
      	at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1179)
      	at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)
      	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
      	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
      	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
      	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
      	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
      	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
      	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
      	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
      	... 11 more
      Caused by: java.sql.BatchUpdateException: Duplicate entry 'API Privileges-Provider App' for key 'PRIMARY'
      	at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2016)
      	at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1452)
      	at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
      	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
      	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
      	... 25 more
      

      Apparently something is broken about a nested role.

        Gliffy Diagrams

          Activity

          Hide
          Rafal Korytkowski added a comment - - edited

          Committed in https://github.com/openmrs/openmrs-module-metadatasharing/commit/241cded04e125cfe7337190ea746a5f357d364e9

          The problem was that we added items to both childRoles and inheritedRoles, which resulted in Hibernate trying to insert them twice to the role_role table (not very clever). I'm not sure if it's a faulty configuration in Role.hbm.xml or we just need to be careful.

          I've implemented MetadateMergeHandler<Role> which makes sure new elements are only added to inheritedRoles and not childRoles.

          Can you please test it Darius and report back? Thanks!

          Show
          Rafal Korytkowski added a comment - - edited Committed in https://github.com/openmrs/openmrs-module-metadatasharing/commit/241cded04e125cfe7337190ea746a5f357d364e9 The problem was that we added items to both childRoles and inheritedRoles, which resulted in Hibernate trying to insert them twice to the role_role table (not very clever). I'm not sure if it's a faulty configuration in Role.hbm.xml or we just need to be careful. I've implemented MetadateMergeHandler<Role> which makes sure new elements are only added to inheritedRoles and not childRoles. Can you please test it Darius and report back? Thanks!
          Hide
          Darius Jazayeri added a comment -

          I tried this out on the kenya example, and it successfully imported. I didn't look at the imported data too closely, but I'm assuming that's fine.

          Thanks!

          Show
          Darius Jazayeri added a comment - I tried this out on the kenya example, and it successfully imported. I didn't look at the imported data too closely, but I'm assuming that's fine. Thanks!
          Hide
          Darius Jazayeri added a comment -

          PS- If you can either release a new version, or give me the go-ahead to release the new version, that would be great!

          Show
          Darius Jazayeri added a comment - PS- If you can either release a new version, or give me the go-ahead to release the new version, that would be great!
          Hide
          Rafal Korytkowski added a comment -

          I'm planning to do a maintenance release on Sunday before the sprint.

          Show
          Rafal Korytkowski added a comment - I'm planning to do a maintenance release on Sunday before the sprint.
          Hide
          Darius Jazayeri added a comment -

          Okay, that should be good enough, thanks!

          Show
          Darius Jazayeri added a comment - Okay, that should be good enough, thanks!

            People

            • Assignee:
              Rafal Korytkowski
              Reporter:
              Darius Jazayeri
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 4 hours Original Estimate - 4 hours
                4h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day
                1d

                  Development