class WorkspaceService {

    public Workspace create(Workspace workspace) {
        try {
            return transactionService.required(() -> workspaceRepository.save(workspace));
        } catch (TransactionExecutionException e) {
            if (e.getCause() instanceof DataIntegrityViolationException) {
                throw new BadRequestException(String.format("Workspace with name '%s' in your tenant already exists.",
                        workspace.getName()), e.getCause());
            }
            throw new TransactionRuntimeExecutionException(e);
        }
    }

}