Extbase Repository objectType = NULL

1k views Asked by At

We are migrating a 4.5 Extension to 7.2. One special case is strange. Trying to get a findOneByUid brings a "No class name was given to retrieve the Data Map for." Error.

Accessing via another object and using the DebuggerUtility it allows us to navigate to the object that fails, and there we can see, the objectType is NULL.

Any clue where to search? All the other objects can be accessed via findOneByUid.

Why is componentRepository objectType = NULL?

How would you proceed to find the issue?

3

There are 3 answers

1
metaxos On

Adding the following lines solved the problem... any idea how to avoid this?

public function __construct() { $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->objectType = \TYPO3\CMS\Core\Utility\ClassNamingUtility::translateRepositoryNameToModelName($this->getRepositoryClassName()); }

0
Alexander Schnitzler On

The object type can only be null if the constructor of the repository has been overridden in a subclass without a call to the parent constructor. parent::__construct();

Instead of using the constructor, you should make use of the method initializeObject, which gets called after the constructor and which can safely be overridden.

0
Vikram On

I had simialr problem (TYPO3 11.5).

Fatal error: Uncaught TypeError: Argument 1 passed to TYPO3\CMS\Extbase\Persistence\Generic\Query::setType() must be of the type string, null given

I got the error beacuse I added function __construct() in the model repository and did not call parent::__construct() and this made $this->objectType = NULL

Solution:

use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;

class MyRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {

        public function __construct(
        ObjectManagerInterface $objectManager,
        ConnectionPool $connectionPool
        ){

        parent::__construct( $objectManager ); 
        $this->connectionPool = $connectionPool;

        }   
}