public function castTypes(Query $query, array $data) {
        if ($columns = $query->getRepository()->getSchema()->getColumns()) {
            foreach ($columns as $column) {
                $field = $column['field'];

                if (array_key_exists($field, $data)) {
                    if ($data[$field] !== null) {
                        $data[$field] = AbstractType::factory($column['type'], $this->getDriver())->to($data[$field]);
                    }
                } else if (in_array($query->getType(), [Query::INSERT, Query::MULTI_INSERT], true) && array_key_exists('default', $column)) {
                    $data[$field] = $column['default'];
                }
            }
        }

        return $data;
    }