Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Error when trying to delete multiple users using UserManager.instance.delete() #4126

mrinal.das ·

I tried to delete multiple(~14000) users from QB in my simple groovy script.

...
UserManager.instance.delete(UserManager.instance.get(id));
...

And I encountered the following error. Please could you check this. :)

Step 'master>Delete_Inactive_Users_30_days' is failed: org.hibernate.exception.ConstraintViolationException: could not execute statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:72) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) .... ... Caused by: java.sql.SQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (<database_name>.QB_MEMBERSHIP, CONSTRAINTFK_MEM_USERFOREIGN KEY (QB_USER_ID) REFERENCESQB_USER(QB_ID)) Query is: /* delete com.pmease.quickbuild.model.User */ delete from QB_USER where QB_ID=?, parameters [8345] at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:119) at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69) at org.mariadb.jdbc.MariaDbStatement.executeQueryEpilog(MariaDbStatement.java:226) at org.mariadb.jdbc.MariaDbServerPreparedStatement.executeInternal(MariaDbServerPreparedStatement.java:376) at org.mariadb.jdbc.MariaDbServerPreparedStatement.execute(MariaDbServerPreparedStatement.java:323) at org.mariadb.jdbc.MariaDbServerPreparedStatement.executeUpdate(MariaDbServerPreparedStatement.java:312) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208) ... 34 more

  • solved #2
  • replies 2
  • views 353
  • stars 0
robinshen ADMIN ·

Please wrap the logic inside a session. Also makes sure to call this script from QB server:

import com.pmease.quickbuild.persistence.*;
SessionManager.openSession();
try {
  UserManager.instance.delete(UserManager.instance.get(id));
} finally {
  SessionManager.closeSession();
}
mrinal.das ·

Thank you.
I was able to delete bulk users next time.