<div dir="ltr">The import is really meant for a clean database. Or at least to import non-existing realms.<div><br></div><div>Why are you doing an import during upgrade if you are not starting with a clean database?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 1 February 2016 at 08:55, Marek Posolda <span dir="ltr"><<a href="mailto:mposolda@redhat.com" target="_blank">mposolda@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div>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<div><div class="h5"><br>
<br>
On 01/02/16 07:47, Hristo Stoyanov wrote:<br>
</div></div></div>
<blockquote type="cite"><div><div class="h5">
<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 style="white-space:pre-wrap">        </span>at
org.keycloak.connections.jpa.PersistenceExceptionConverter.convert(PersistenceExceptionConverter.java:40)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.connections.jpa.PersistenceExceptionConverter.invoke(PersistenceExceptionConverter.java:34)</div>
<div><span style="white-space:pre-wrap">        </span>at
com.sun.proxy.$Proxy83.flush(Unknown Source)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.models.jpa.JpaUserProvider.addUser(JpaUserProvider.java:61)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.models.cache.infinispan.DefaultCacheUserProvider.addUser(DefaultCacheUserProvider.java:267)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.models.utils.RepresentationToModel.createUser(RepresentationToModel.java:1168)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.exportimport.util.ImportUtils.importUsers(ImportUtils.java:191)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.exportimport.util.ImportUtils.importUsersFromStream(ImportUtils.java:175)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.exportimport.dir.DirImportProvider$4.runExportImportTask(DirImportProvider.java:121)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.exportimport.util.ExportImportSessionTask.run(ExportImportSessionTask.java:18)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.models.utils.KeycloakModelUtils.runJobInTransaction(KeycloakModelUtils.java:267)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.exportimport.dir.DirImportProvider.importRealm(DirImportProvider.java:117)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.exportimport.dir.DirImportProvider.importModel(DirImportProvider.java:55)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.exportimport.ExportImportManager.runImport(ExportImportManager.java:69)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.services.resources.KeycloakApplication.<init>(KeycloakApplication.java:107)</div>
<div><span style="white-space:pre-wrap">        </span>at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)</div>
<div><span style="white-space:pre-wrap">        </span>at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)</div>
<div><span style="white-space:pre-wrap">        </span>at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)</div>
<div><span style="white-space:pre-wrap">        </span>at
java.lang.reflect.Constructor.newInstance(Constructor.java:422)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:150)</div>
<div><span style="white-space:pre-wrap">        </span>... 19
more</div>
<div>Caused by: javax.persistence.PersistenceException:
org.hibernate.exception.ConstraintViolationException: could
not execute statement</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1303)</div>
<div><span style="white-space:pre-wrap">        </span>at
sun.reflect.GeneratedMethodAccessor300.invoke(Unknown
Source)</div>
<div><span style="white-space:pre-wrap">        </span>at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div>
<div><span style="white-space:pre-wrap">        </span>at
java.lang.reflect.Method.invoke(Method.java:497)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.keycloak.connections.jpa.PersistenceExceptionConverter.invoke(PersistenceExceptionConverter.java:32)</div>
<div><span style="white-space:pre-wrap">        </span>... 37
more</div>
<div>Caused by:
org.hibernate.exception.ConstraintViolationException: could
not execute statement</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2886)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3386)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1300)</div>
<div><span style="white-space:pre-wrap">        </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 style="white-space:pre-wrap">        </span>at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1911)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:173)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:645)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:495)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:441)</div>
<div><span style="white-space:pre-wrap">        </span>at
sun.reflect.GeneratedMethodAccessor295.invoke(Unknown
Source)</div>
<div><span style="white-space:pre-wrap">        </span>at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)</div>
<div><span style="white-space:pre-wrap">        </span>at
java.lang.reflect.Method.invoke(Method.java:497)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.invoke(AbstractJdbc23PooledConnection.java:453)</div>
<div><span style="white-space:pre-wrap">        </span>at
com.sun.proxy.$Proxy84.executeUpdate(Unknown Source)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:537)</div>
<div><span style="white-space:pre-wrap">        </span>at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)</div>
</div>
<div><br>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
keycloak-user mailing list
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank">keycloak-user@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br></blockquote></div><br></div>