Program: 160353
Project: 160353
Buggy source:
@Override public void pluginInstalled(long pluginBundleVersionId,PluginContext pluginContext,SPluginInformation sPluginInformation) throws BimserverDatabaseException {
  try (DatabaseSession session=bimDatabase.createSession()){
    Plugin plugin=pluginContext.getPlugin();
    PluginDescriptor pluginDescriptor=session.create(PluginDescriptor.class);
    pluginDescriptor.setIdentifier(pluginContext.getIdentifier());
    pluginDescriptor.setPluginClassName(plugin.getClass().getName());
    pluginDescriptor.setDescription(pluginContext.getDescription());
    pluginDescriptor.setName(sPluginInformation.getName());
    pluginDescriptor.setLocation(pluginContext.getLocation().toString());
    pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
    pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
    pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
    pluginDescriptor.setPluginBundleVersion(session.get(pluginBundleVersionId,OldQuery.getDefault()));
    if (sPluginInformation.isInstallForAllUsers()) {
      IfcModelInterface allOfType=session.getAllOfType(StorePackage.eINSTANCE.getUser(),OldQuery.getDefault());
      for (      User user : allOfType.getAll(User.class)) {
        if (user.getState() == ObjectState.ACTIVE) {
          updateUserPlugin(session,user,pluginDescriptor,pluginContext);
        }
      }
    }
    if (pluginContext.getPlugin() instanceof WebModulePlugin) {
      ServerSettings serverSettings=getServerSettingsCache().getServerSettings();
      WebModulePluginConfiguration webPluginConfiguration=find(serverSettings.getWebModules(),pluginContext.getIdentifier());
      if (webPluginConfiguration == null) {
        webPluginConfiguration=session.create(WebModulePluginConfiguration.class);
        serverSettings.getWebModules().add(webPluginConfiguration);
        genericPluginConversion(pluginContext,session,webPluginConfiguration,pluginDescriptor);
        session.store(serverSettings);
      }
      String contextPath="String_Node_Str";
      for (      Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
        if (parameter.getName().equals("String_Node_Str")) {
          contextPath=((StringType)parameter.getValue()).getValue();
        }
      }
      webModules.put(contextPath,(WebModulePlugin)pluginManager.getPlugin(pluginContext.getIdentifier(),true));
    }
    try {
      session.commit();
    }
 catch (    ServiceException e) {
      LOGGER.error("String_Node_Str",e);
    }
  }
 }

Fixed version (ground truth):
@Override public void pluginInstalled(long pluginBundleVersionId,PluginContext pluginContext,SPluginInformation sPluginInformation) throws BimserverDatabaseException {
  try (DatabaseSession session=bimDatabase.createSession()){
    Plugin plugin=pluginContext.getPlugin();
    Condition pluginCondition=new AttributeCondition(StorePackage.eINSTANCE.getPluginDescriptor_Identifier(),new StringLiteral(pluginContext.getIdentifier()));
    Map<Long,PluginDescriptor> pluginsFound=session.query(pluginCondition,PluginDescriptor.class,OldQuery.getDefault());
    PluginDescriptor pluginDescriptor=null;
    if (pluginsFound.size() > 0) {
      pluginDescriptor=pluginsFound.values().iterator().next();
    }
 else {
      pluginDescriptor=session.create(PluginDescriptor.class);
    }
    pluginDescriptor.setIdentifier(pluginContext.getIdentifier());
    pluginDescriptor.setPluginClassName(plugin.getClass().getName());
    pluginDescriptor.setDescription(pluginContext.getDescription());
    pluginDescriptor.setName(sPluginInformation.getName());
    pluginDescriptor.setLocation(pluginContext.getLocation().toString());
    pluginDescriptor.setPluginInterfaceClassName(getPluginInterface(plugin.getClass()).getName());
    pluginDescriptor.setEnabled(sPluginInformation.isEnabled());
    pluginDescriptor.setInstallForNewUsers(sPluginInformation.isInstallForNewUsers());
    pluginDescriptor.setPluginBundleVersion(session.get(pluginBundleVersionId,OldQuery.getDefault()));
    if (sPluginInformation.isInstallForAllUsers()) {
      IfcModelInterface allOfType=session.getAllOfType(StorePackage.eINSTANCE.getUser(),OldQuery.getDefault());
      for (      User user : allOfType.getAll(User.class)) {
        if (user.getState() == ObjectState.ACTIVE) {
          updateUserPlugin(session,user,pluginDescriptor,pluginContext);
        }
      }
    }
    if (pluginContext.getPlugin() instanceof WebModulePlugin) {
      ServerSettings serverSettings=getServerSettingsCache().getServerSettings();
      WebModulePluginConfiguration webPluginConfiguration=find(serverSettings.getWebModules(),pluginContext.getIdentifier());
      if (webPluginConfiguration == null) {
        webPluginConfiguration=session.create(WebModulePluginConfiguration.class);
        serverSettings.getWebModules().add(webPluginConfiguration);
        genericPluginConversion(pluginContext,session,webPluginConfiguration,pluginDescriptor);
        session.store(serverSettings);
      }
      String contextPath="String_Node_Str";
      for (      Parameter parameter : webPluginConfiguration.getSettings().getParameters()) {
        if (parameter.getName().equals("String_Node_Str")) {
          contextPath=((StringType)parameter.getValue()).getValue();
        }
      }
      webModules.put(contextPath,(WebModulePlugin)pluginManager.getPlugin(pluginContext.getIdentifier(),true));
    }
    try {
      session.commit();
    }
 catch (    ServiceException e) {
      LOGGER.error("String_Node_Str",e);
    }
  }
 }