@Override public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { Entity entity = persistencePackage.getEntity(); try { PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective(); Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance(); adminInstance.setId(customerService.findNextCustomerId()); Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective); adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false); if (useEmailForLogin) { adminInstance.setUsername(adminInstance.getEmailAddress()); } Entity errorEntity = validateUniqueUsername(entity, adminInstance, true); if (errorEntity != null) { return errorEntity; } adminInstance = dynamicEntityDao.merge(adminInstance); customerService.createRegisteredCustomerRoles(adminInstance); Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null); return adminEntity; } catch (Exception e) { LOG.error("Unable to execute persistence activity", e); throw new ServiceException("Unable to add entity for " + entity.getType()[0], e); } }