title: Doctrine: custom entity repository
body: <p>Have some problems with building custom entity repository.</p>
  
  <p>I have the following fatal error while trying method of custom entity repository</p>
  
  <pre><code>Fatal error: Uncaught exception 'BadMethodCallException' with message 'Undefined method 'getByParentId'. The method name must start with either findBy or findOneBy!' in C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\EntityRepository.php:215 Stack trace: #0 C:\Users\user\Desktop\projects\interview\application\controllers\CommentController.php(58): Doctrine\ORM\EntityRepository-&gt;__call('getByParentId', Array) #1 C:\Users\user\Desktop\projects\interview\application\controllers\CommentController.php(58): Doctrine\ORM\EntityRepository-&gt;getByParentId('1') #2 [internal function]: CommentController-&gt;viewCommentsListByParentId('1') #3 C:\Users\user\Desktop\projects\interview\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #4 C:\Users\user\Desktop\projects\interview\index.php(203): require_once('C:\Users\user\D...') #5 {main} thrown in C:\Users\user\Desktop\projects\interview\application\libraries\Doctrine\ORM\EntityRepository.php on line 215
  </code></pre>
  
  <p>My project structure is
  models
    Mappings
    Repositories
    Entities
    Proxies</p>
  
  <p>My doctrine.php has repository loader like this</p>
  
  <pre><code>// load the repositories
  $repositoryClassLoader = new \Doctrine\Common\ClassLoader('Repositories', APPPATH.'models');
  $repositoryClassLoader-&gt;register();
  </code></pre>
  
  <p>My model class has the following declaration</p>
  
  <pre><code>namespace Entities;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * Entities\Comment
   * @Entity (repositoryClass="Repositories\CommentRepository")
   */
  class Comment
  {
  </code></pre>
  
  <p>My Repository class has the following declaration</p>
  
  <pre><code>namespace Repositories;
  use Doctrine\ORM\EntityRepository;
  use Entities;
  
  class CommentRepository extends EntityRepository {
      public function getByParentId($parentid) {
          return parent::findBy(array('parentid' =&gt; $parentid), array('creationdate' =&gt; 'DESC'));
      }
  }
  </code></pre>
  
  <p>Controller code calling for methods of custom repository</p>
  
  <pre><code>   public function viewCommentsListByParentId($parentid) {
          $data = array();
          $data ['comment'] = $this-&gt;em-&gt;getRepository('Entities\Comment')-&gt;getByParentId($parentid);
  
          $this-&gt;load-&gt;view('commentsList', $data);
      } 
  </code></pre>
  
  <p>What I'm doing wrong??? Please, help. </p>
  
  <hr>
  
  <pre><code>object(Doctrine\ORM\Mapping\ClassMetadata)#34 (32) {
      ["name"]=&gt; string(16) "Entities\Comment"
      ["namespace"]=&gt; string(8) "Entities"
      ["rootEntityName"]=&gt; string(16) "Entities\Comment"
      ["customRepositoryClassName"]=&gt; NULL
      ["isMappedSuperclass"]=&gt; bool(false)
      ["parentClasses"]=&gt; array(0) { }
      ["subClasses"]=&gt; array(0) { }
      ["namedQueries"]=&gt; array(0) { }
      ["identifier"]=&gt; array(1) {
          [0]=&gt; string(2) "id"
      }
      ["inheritanceType"]=&gt; int(1)
      ["generatorType"]=&gt; int(4)
      ["fieldMappings"]=&gt; array(11) {
          ["id"]=&gt; array(4) {
              ["fieldName"]=&gt; string(2) "id"
              ["type"]=&gt; string(7) "integer"
              ["id"]=&gt; bool(true)
              ["columnName"]=&gt; string(2) "id"
          }
          ["parentid"]=&gt; array(4) {
              ["fieldName"]=&gt; string(8) "parentid"
              ["type"]=&gt; string(7) "integer"
              ["columnName"]=&gt; string(8) "parentid"
              ["nullable"]=&gt; bool(false)
          }
          ["isactive"]=&gt; array(4) {
              ["fieldName"]=&gt; string(8) "isactive"
              ["type"]=&gt; string(7) "integer"
              ["columnName"]=&gt; string(8) "isactive"
              ["nullable"]=&gt; bool(false)
          }
          ["isremoved"]=&gt; array(4) {
              ["fieldName"]=&gt; string(9) "isremoved"
              ["type"]=&gt; string(7) "integer"
              ["columnName"]=&gt; string(9) "isremoved"
              ["nullable"]=&gt; bool(false)
          }
          ["removaldate"]=&gt; array(4) {
              ["fieldName"]=&gt; string(11) "removaldate"
              ["type"]=&gt; string(8) "datetime"
              ["columnName"]=&gt; string(11) "removaldate"
              ["nullable"]=&gt; bool(true)
          }
          ["user_name"]=&gt; array(5) {
              ["fieldName"]=&gt; string(9) "user_name"
              ["type"]=&gt; string(6) "string"
              ["columnName"]=&gt; string(9) "user_name"
              ["length"]=&gt; int(255)
              ["nullable"]=&gt; bool(false)
          }
          ["user_email"]=&gt; array(5) {
              ["fieldName"]=&gt; string(10) "user_email"
              ["type"]=&gt; string(6) "string"
              ["columnName"]=&gt; string(10) "user_email"
              ["length"]=&gt; int(255)
              ["nullable"]=&gt; bool(false)
          }
          ["user_avatar"]=&gt; array(5) {
              ["fieldName"]=&gt; string(11) "user_avatar"
              ["type"]=&gt; string(6) "string"
              ["columnName"]=&gt; string(11) "user_avatar"
              ["length"]=&gt; int(255)
              ["nullable"]=&gt; bool(false)
          }
          ["comment"]=&gt; array(4) {
              ["fieldName"]=&gt; string(7) "comment"
              ["type"]=&gt; string(4) "text"
              ["columnName"]=&gt; string(7) "comment"
              ["nullable"]=&gt; bool(false)
          }
          ["creationdate"]=&gt; array(4) {
              ["fieldName"]=&gt; string(12) "creationdate"
              ["type"]=&gt; string(8) "datetime"
              ["columnName"]=&gt; string(12) "creationdate"
              ["nullable"]=&gt; bool(false)
          }
          ["rating"]=&gt; array(4) {
              ["fieldName"]=&gt; string(6) "rating"
              ["type"]=&gt; string(7) "integer"
              ["nullable"]=&gt; bool(false)
              ["columnName"]=&gt; string(6) "rating"
          }
      }
      ["fieldNames"]=&gt; array(11) {
          ["id"]=&gt; string(2) "id"
          ["parentid"]=&gt; string(8) "parentid"
          ["isactive"]=&gt; string(8) "isactive"
          ["isremoved"]=&gt; string(9) "isremoved"
          ["removaldate"]=&gt; string(11) "removaldate"
          ["user_name"]=&gt; string(9) "user_name"
          ["user_email"]=&gt; string(10) "user_email"
          ["user_avatar"]=&gt; string(11) "user_avatar"
          ["comment"]=&gt; string(7) "comment"
          ["creationdate"]=&gt; string(12) "creationdate"
          ["rating"]=&gt; string(6) "rating"
      }
      ["columnNames"]=&gt; array(11) {
          ["id"]=&gt; string(2) "id"
          ["parentid"]=&gt; string(8) "parentid"
          ["isactive"]=&gt; string(8) "isactive"
          ["isremoved"]=&gt; string(9) "isremoved"
          ["removaldate"]=&gt; string(11) "removaldate"
          ["user_name"]=&gt; string(9) "user_name"
          ["user_email"]=&gt; string(10) "user_email"
          ["user_avatar"]=&gt; string(11) "user_avatar"
          ["comment"]=&gt; string(7) "comment"
          ["creationdate"]=&gt; string(12) "creationdate"
          ["rating"]=&gt; string(6) "rating"
      }
      ["discriminatorValue"]=&gt; NULL
      ["discriminatorMap"]=&gt; array(0) { }
      ["discriminatorColumn"]=&gt; NULL
      ["table"]=&gt; array(1) {
          ["name"]=&gt; string(7) "Comment"
      }
      ["lifecycleCallbacks"]=&gt; array(0) { }
      ["associationMappings"]=&gt; array(0) { }
      ["isIdentifierComposite"]=&gt; bool(false)
      ["containsForeignIdentifier"]=&gt; bool(false)
      ["idGenerator"]=&gt; object(Doctrine\ORM\Id\IdentityGenerator)#40 (1) {
          ["_seqName":"Doctrine\ORM\Id\IdentityGenerator":private]=&gt; NULL
      }
      ["sequenceGeneratorDefinition"]=&gt; NULL
      ["tableGeneratorDefinition"]=&gt; NULL
      ["changeTrackingPolicy"]=&gt; int(1)
      ["isVersioned"]=&gt; NULL
      ["versionField"]=&gt; NULL
      ["reflClass"]=&gt; object(ReflectionClass)#41 (1) {
          ["name"]=&gt; string(16) "Entities\Comment"
      }
      ["isReadOnly"]=&gt; bool(false)
      ["reflFields"]=&gt; array(11) {
          ["id"]=&gt; object(ReflectionProperty)#35 (2) {
              ["name"]=&gt; string(2) "id"
              ["class"]=&gt; string(16) "Entities\Comment"
          }
          ["parentid"]=&gt; object(ReflectionProperty)#42 (2) {
              ["name"]=&gt; string(8) "parentid"
              ["class"]=&gt; string(16) "Entities\Comment"
          }
          ["isactive"]=&gt; object(ReflectionProperty)#43 (2) {
              ["name"]=&gt; string(8) "isactive"
              ["class"]=&gt; string(16) "Entities\Comment"
          }
          ["isremoved"]=&gt; object(ReflectionProperty)#44 (2) {
              ["name"]=&gt; string(9) "isremoved" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
          ["removaldate"]=&gt; object(ReflectionProperty)#45 (2) { 
              ["name"]=&gt; string(11) "removaldate" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
          ["user_name"]=&gt; object(ReflectionProperty)#46 (2) { 
              ["name"]=&gt; string(9) "user_name" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
          ["user_email"]=&gt; object(ReflectionProperty)#47 (2) { 
              ["name"]=&gt; string(10) "user_email" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
          ["user_avatar"]=&gt; object(ReflectionProperty)#48 (2) { 
              ["name"]=&gt; string(11) "user_avatar" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
          ["comment"]=&gt; object(ReflectionProperty)#49 (2) { 
              ["name"]=&gt; string(7) "comment" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
          ["creationdate"]=&gt; object(ReflectionProperty)#50 (2) { 
              ["name"]=&gt; string(12) "creationdate" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
          ["rating"]=&gt; object(ReflectionProperty)#51 (2) { 
              ["name"]=&gt; string(6) "rating" 
              ["class"]=&gt; string(16) "Entities\Comment" 
          } 
      } 
      ["_prototype":"Doctrine\ORM\Mapping\ClassMetadataInfo":private]=&gt; NULL 
  }
  </code></pre>