<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def raw(self, query: Any, data: Any = None):
 """Runs raw query directly on the database and returns Entity objects Note that this method will raise an exception if the returned objects are not of the Entity type. `query` is not checked for correctness or validity, and any errors thrown by the plugin or database are passed as-is. Data passed will be transferred as-is to the plugin. All other query options like `order_by`, `offset` and `limit` are ignored for this action. """

        logger.debug(f'Query `{self.__class__.__name__}` objects with raw query {query}')

        # Destroy any cached results
        self._result_cache = None

        # Fetch Model class and connected repository from Repository Factory
        model_cls = repo_factory.get_model(self._entity_cls)
        repository = repo_factory.get_repository(self._entity_cls)

        try:
            # Call the raw method of the repository
            results = repository.raw(query, data)

            # Convert the returned results to entity and return it
            entity_items = []
            for item in results.items:
                entity = model_cls.to_entity(item)
                entity.state_.mark_retrieved()
                entity_items.append(entity)
            results.items = entity_items

            # Cache results
            self._result_cache = results
        except Exception:
            # FIXME Log Exception
            raise

        return results