<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi,<br>
      <br>
      could you please create JIRA? Until it's fixed, I suggest to
      backup your DB and instead use strategy OVERWRITE_EXISTING (or
      just remove strategy property as OVERWRITE_EXISTING is the
      default)<br>
      <br>
      Marek<br>
      <br>
      On 01/02/16 07:47, Hristo Stoyanov wrote:<br>
    </div>
    <blockquote
cite="mid:CAHiHDeRmDvwT1cY6j5znOVAoiSrwdNVqSGGVoHdmUyR1AJxgZQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi all,
        <div>I ma trying to install KC1.8.Final over a previous KC1.7
          installation backed by Postgres. I use template files to
          bootstrap my realm:</div>
        <div><br>
        </div>
        <div>
          <div>36 -rw-r--r-- 1 root root 36806 Feb  1 05:50
            FinancialApps-realm.json</div>
          <div>40 -rw-r--r-- 1 root root 39545 Feb  1 05:50
            master-realm.json</div>
          <div> 4 -rw-r--r-- 1 root root   709 Feb  1 05:50
            master-users-0.json</div>
          <div> 4 -rw-r--r-- 1 root root    77 Feb  1 05:50 version.json</div>
        </div>
        <div><br>
        </div>
        <div>and I use the import facility:</div>
        <div><br>
        </div>
        <div>
          <div>            -Dkeycloak.migration.action=import \</div>
          <div>            -Dkeycloak.migration.provider=dir \</div>
          <div>           
            -Dkeycloak.migration.dir={{wildfly_home}}/keycloak \</div>
          <div>            -Dkeycloak.migration.strategy=IGNORE_EXISTING</div>
        </div>
        <div><br>
        </div>
        <div>Below is the exception I get. I understand that I can wipe
          out my Postgress database and have a clean import, but I
          thought the import was careful enough to check for duplicate
          keys???</div>
        <div>=================================================================</div>
        <div>
          <div>Caused by: org.keycloak.models.ModelDuplicateException:
            javax.persistence.PersistenceException:
            org.hibernate.exception.ConstraintViolationException: could
            not execute statement</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.connections.jpa.PersistenceExceptionConverter.convert(PersistenceExceptionConverter.java:40)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.connections.jpa.PersistenceExceptionConverter.invoke(PersistenceExceptionConverter.java:34)</div>
          <div><span class="" style="white-space:pre">        </span>at
            com.sun.proxy.$Proxy83.flush(Unknown Source)</div>
          <div><span class="" style="white-space:pre">        </span>at
            org.keycloak.models.jpa.JpaUserProvider.addUser(JpaUserProvider.java:61)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.models.cache.infinispan.DefaultCacheUserProvider.addUser(DefaultCacheUserProvider.java:267)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.models.utils.RepresentationToModel.createUser(RepresentationToModel.java:1168)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.exportimport.util.ImportUtils.importUsers(ImportUtils.java:191)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.exportimport.util.ImportUtils.importUsersFromStream(ImportUtils.java:175)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.exportimport.dir.DirImportProvider$4.runExportImportTask(DirImportProvider.java:121)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.exportimport.util.ExportImportSessionTask.run(ExportImportSessionTask.java:18)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:267)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.exportimport.dir.DirImportProvider.importRealm(DirImportProvider.java:117)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.exportimport.dir.DirImportProvider.importModel(DirImportProvider.java:55)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.exportimport.ExportImportManager.runImport(ExportImportManager.java:69)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.services.resources.KeycloakApplication.&lt;init&gt;(KeycloakApplication.java:107)</div>
          <div><span class="" style="white-space:pre">        </span>at
            sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
            Method)</div>
          <div><span class="" style="white-space:pre">        </span>at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)</div>
          <div><span class="" style="white-space:pre">        </span>at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)</div>
          <div><span class="" style="white-space:pre">        </span>at
            java.lang.reflect.Constructor.newInstance(Constructor.java:422)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:150)</div>
          <div><span class="" style="white-space:pre">        </span>... 19
            more</div>
          <div>Caused by: javax.persistence.PersistenceException:
            org.hibernate.exception.ConstraintViolationException: could
            not execute statement</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1303)</div>
          <div><span class="" style="white-space:pre">        </span>at
            sun.reflect.GeneratedMethodAccessor300.invoke(Unknown
            Source)</div>
          <div><span class="" style="white-space:pre">        </span>at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div>
          <div><span class="" style="white-space:pre">        </span>at
            java.lang.reflect.Method.invoke(Method.java:497)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.keycloak.connections.jpa.PersistenceExceptionConverter.invoke(PersistenceExceptionConverter.java:32)</div>
          <div><span class="" style="white-space:pre">        </span>... 37
            more</div>
          <div>Caused by:
            org.hibernate.exception.ConstraintViolationException: could
            not execute statement</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2886)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3386)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)</div>
          <div><span class="" style="white-space:pre">        </span>at
            org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1300)</div>
          <div><span class="" style="white-space:pre">        </span>... 41
            more</div>
          <div><b>Caused by: org.postgresql.util.PSQLException: ERROR:
              duplicate key value violates unique constraint
              "uk_ru8tt6t700s9v50bu18ws5ha6"</b></div>
          <div><b>  Detail: Key (realm_id, username)=(master, admin)
              already exists.</b></div>
          <div><span class="" style="white-space:pre">        </span>at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1911)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:173)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:645)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:495)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:441)</div>
          <div><span class="" style="white-space:pre">        </span>at
            sun.reflect.GeneratedMethodAccessor295.invoke(Unknown
            Source)</div>
          <div><span class="" style="white-space:pre">        </span>at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div>
          <div><span class="" style="white-space:pre">        </span>at
            java.lang.reflect.Method.invoke(Method.java:497)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.invoke(AbstractJdbc23PooledConnection.java:453)</div>
          <div><span class="" style="white-space:pre">        </span>at
            com.sun.proxy.$Proxy84.executeUpdate(Unknown Source)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:537)</div>
          <div><span class="" style="white-space:pre">        </span>at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)</div>
        </div>
        <div><br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </body>
</html>