droitatedDB/src/main/java/org/droitateddb/EntityService.java
public long save(final E data, final int maxDepth) {
        if (toggle == ValidationToggle.ON) {
            AccumulatedValidationResult validationResult = databaseValidator.validate(data, maxDepth);
            if (!validationResult.isValid()) {
                throw new InvalidEntityException(validationResult);
            }
        }

        final SQLiteDatabase database = openDB();
        try {
            return transactional(database, new DatabaseOperation<Number>() {
                @Override
                public Number execute() {
                    return new DatabaseSaver(database, maxDepth).save(data);
                }
            }).longValue();
        } finally {
            closeDB(database);
        }
    }
public long save(final E data, final int maxDepth) {
        if (toggle == ValidationToggle.ON) {
            AccumulatedValidationResult validationResult = databaseValidator.validate(data, maxDepth);
            if (!validationResult.isValid()) {
                throw new InvalidEntityException(validationResult);
            }
        }

        final SQLiteDatabase database = openDB();
        try {
            return transactional(database, new DatabaseOperation<Number>() {
                @Override
                public Number execute() {
                    return new DatabaseSaver(database, maxDepth).save(data);
                }
            }).longValue();
        } finally {
            closeDB(database);
        }
    }
Stores the given {@link Entity} to the database. Associated objects will be saved to the given maxDepth.<br>
maxDepth of 0 means that only the given {@link Entity} itself will be saved without associations.

@param data     {@link Entity} which should be stored
@param maxDepth The maximum depth of the associated objects which should also be saved.
@return The primary key of the given data.
@throws IllegalStateException                             When the {@link PrimaryKey} field and its value of the {@link Entity} could
not be determined
@throws org.droitateddb.validation.InvalidEntityException when the given entity is invalid.