@Transactional
  public RepositoryVersionEntity create(StackEntity stackEntity,
                                        String version, String displayName, List<RepoOsEntity> repoOsEntities,
                                        RepositoryType type) throws AmbariException {

    if (stackEntity == null || version == null || version.isEmpty()
        || displayName == null || displayName.isEmpty()) {
      throw new AmbariException("At least one of the required properties is null or empty");
    }

    RepositoryVersionEntity existingByDisplayName = findByDisplayName(displayName);

    if (existingByDisplayName != null) {
      throw new AmbariException("Repository version with display name '" + displayName + "' already exists");
    }

    RepositoryVersionEntity existingVersionInStack = findByStackNameAndVersion(stackEntity.getStackName(), version);

    if (existingVersionInStack != null) {
      throw new AmbariException(MessageFormat.format("Repository Version for version {0} already exists, in stack {1}-{2}",
          version, existingVersionInStack.getStack().getStackName(), existingVersionInStack.getStack().getStackVersion()));
    }


    StackId stackId = new StackId(stackEntity.getStackName(), stackEntity.getStackVersion() );
    if (!RepositoryVersionEntity.isVersionInStack(stackId, version)) {
      throw new AmbariException(MessageFormat.format("Version {0} needs to belong to stack {1}", version, stackEntity.getStackName() + "-" + stackEntity.getStackVersion()));
    }

    RepositoryVersionEntity newEntity = new RepositoryVersionEntity(
        stackEntity, version, displayName, repoOsEntities);
    newEntity.setType(type);
    this.create(newEntity);
    return newEntity;
  }
Validates and creates an object.
The version must be unique within this stack name (e.g., HDP, HDPWIN, BIGTOP).
@param stackEntity Stack entity.
@param version Stack version, e.g., 2.2 or 2.2.0.1-885
@param displayName Unique display name
@param repoOsEntities structure of repository URLs for each OS
@param type  the repository type
@return Returns the object created if successful, and throws an exception otherwise.
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RepositoryVersionDAO.java