private EntityObject AddObjectToDB(EntityObject obj)
            throws DataProviderAddingException {

        if (!obj.getClass().isAnnotationPresent(Entity.class)) {
            throw new DataProviderAddingException(obj.getClass());
        }

        boolean generated = true;
        // is id auto generated
        List<Field> idFields = AnnotationManager.getFieldsByAnnotation(obj.getClass(), EntityId.class);
        if (!idFields.isEmpty()) {
            generated = idFields.get(0).isAnnotationPresent(AutoIncremented.class);
        }

        Integer relObjId = (Integer) obj.getEntityId();
        // if relObj are not in DB
        if (relObjId == null || relObjId.equals(0) || !generated) {
            // try to find entity in db
            EntityObject uniqObj = (EntityObject) this.checkUnique(obj);

            if (uniqObj == null) {
                // add Entity
                MethodResult relResult = this.addEntity(obj, false);

                if (!relResult.isSuccessful()) {
                    throw new DataProviderAddingException(obj.getClass());
                }
                if (DEBUG) {
                    System.out.printf("%s has been successfully added to db\r\n", obj.toString());
                }
            } else {
                obj.setEntityId(uniqObj.getEntityId());
                if (DEBUG) {
                    System.out.printf("Entity %s is already exists in db\r\n", obj.toString());
                }
            }
        }

        return obj;

    }