2

I do have a really weird problem and searched&tried different approaches. As my title states my Entities (with all of them!) are not working - mean their cant mapped.

Ill come fast to the point:

Extension Array

Array ( [0] => Core [1] => date [2] => ereg [3] => libxml [4] => openssl [5] => pcre [6] => sqlite3 [7] => zlib [8] => bcmath [9] => bz2 [10] => calendar [11] => ctype [12] => curl [13] => dba [14] => dom [15] => hash [16] => fileinfo [17] => filter [18] => ftp [19] => gd [20] => gettext [21] => gmp [22] => SPL [23] => iconv [24] => session [25] => intl [26] => json [27] => ldap [28] => mbstring [29] => mcrypt [30] => mssql [31] => mysql [32] => standard [33] => PDO [34] => pdo_dblib [35] => mysqlnd [36] => pdo_sqlite [37] => pgsql [38] => apc [39] => posix [40] => Reflection [41] => imap [42] => shmop [43] => SimpleXML [44] => snmp [45] => soap [46] => sockets [47] => pdo_mysql [48] => exif [49] => sysvmsg [50] => sysvsem [51] => sysvshm [52] => tidy [53] => tokenizer [54] => wddx [55] => xml [56] => xmlreader [57] => xmlrpc [58] => xmlwriter [59] => xsl [60] => zip [61] => mysqli [62] => apache2handler [63] => Phar [64] => mhash )

So far with I came up with and tried to fix:

  1. APC on (no eAcc which mostly caused the problem) REF:("Class XXX is not a valid entity or mapped super class" after moving the class in the filesystem)
  2. Delete the Doctrine Folder in Resources, cleared the cache. No sucess.
  3. Addded full namespaces to the config ORM's entity // change: "company" to "x/basebundle/entity/company" doesn't worked so reverted changes.
  4. I Do no use annoations, Iam using yml.
  5. Auto Mapping is true!

Resources/Config/Doctrine/Websites.orm.yml takes the entity class as first argument:

Brenne\BaseBundle\Entity\Website:
    type: entity
    table: website
    repositoryClass: Brenne\BaseBundle\Repository\WebsiteRepository
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 110
            nullable: true
        url:
            type: string
            length: 255
            nullable: true
        logo:
            type: string
            length: 255
            nullable: true
        description:
            type: text
    oneToMany:
        assignedPing:
            targetEntity: ping
            mappedBy: website
    manyToOne:
        company:
          targetEntity: Company
          inversedBy: website

/Entity/Websites.orm.yml takes the entity class as first argument:

<?php

namespace Brenne\BaseBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Website
 */
class Website
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $url;

    /**
     * @var string
     */
    private $logo;

    /**
     * @var string
     */
    private $description;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $assignedPing;

    /**
     * @var \Brenne\BaseBundle\Entity\Company
     */
    private $company;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->assignedPing = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Website
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set url
     *
     * @param string $url
     * @return Website
     */
    public function setUrl($url)
    {
        $this->url = $url;

        return $this;
    }

    /**
     * Get url
     *
     * @return string 
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * Set logo
     *
     * @param string $logo
     * @return Website
     */
    public function setLogo($logo)
    {
        $this->logo = $logo;

        return $this;
    }

    /**
     * Get logo
     *
     * @return string 
     */
    public function getLogo()
    {
        return $this->logo;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Website
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Add assignedPing
     *
     * @param \Brenne\BaseBundle\Entity\ping $assignedPing
     * @return Website
     */
    public function addAssignedPing(\Brenne\BaseBundle\Entity\ping $assignedPing)
    {
        $this->assignedPing[] = $assignedPing;

        return $this;
    }

    /**
     * Remove assignedPing
     *
     * @param \Brenne\BaseBundle\Entity\ping $assignedPing
     */
    public function removeAssignedPing(\Brenne\BaseBundle\Entity\ping $assignedPing)
    {
        $this->assignedPing->removeElement($assignedPing);
    }

    /**
     * Get assignedPing
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getAssignedPing()
    {
        return $this->assignedPing;
    }

    /**
     * Set company
     *
     * @param \Brenne\BaseBundle\Entity\Company $company
     * @return Website
     */
    public function setCompany(\Brenne\BaseBundle\Entity\Company $company = null)
    {
        $this->company = $company;

        return $this;
    }

    /**
     * Get company
     *
     * @return \Brenne\BaseBundle\Entity\Company 
     */
    public function getCompany()
    {
        return $this->company;
    }
}

I dont know anyhting else to do, may you come up with an idea! Thanks for your time.

Community
  • 1
  • 1
s1x
  • 574
  • 4
  • 15

3 Answers3

2

You have to name the mapping files and folders where you store them exactly as per convention.

... Otherwise you'll face invalid mapping classmetadata or errors when loading the files.

Keep in mind that files and folders are case sensitive on some systems.

Solution:

The mapping file should be read:

  • Website.orm.yml
  • ... or ...
  • Brenne.BaseBundle.Entity.Website.orm.yml

and it should live in the folder ...

src/Brenne/BaseBundle/Resources/config/doctrine

Please be careful with the naming ( config, doctrine - small caps, Website without s )...


clear your symfony cache for the correct environment (app/console ca:c --env=.. or rm -rf app/cache/*) and restart your webserver / fpm-pool (in order to clear cached metadata from APC and opcache )

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • This worked for me. It seems really important, first that you don't have `Invalid Entities` and second taking care of case sensitive file/folders as the wrong small caps on `ping`@oneToMany Website broke it. So **take care** of **case sensitive** files/folders! – s1x Jan 30 '14 at 00:57
  • i'm glad you were able to resolve your issue :) thanks for reporting back. – Nicolai Fröhlich Jan 30 '14 at 02:15
0

Try to use \ in front of namespace:

\Brenne\BaseBundle\Entity\Websites:
type: entity
table: websites
repositoryClass: \Brenne\BaseBundle\Repository\WebsitesRepository
Victor Bocharsky
  • 11,930
  • 13
  • 58
  • 91
  • Didn't helped in this case. However if I added \ infront of the namespace it stopped working at my local machine (Windows Xampp). Anyhow the error (with and without \) is the same on the production server. – s1x Jan 29 '14 at 20:53
  • Just discovered: I do have 3 invalid entties on my localhost. Could this be a problem? Dunno how to fix them to be honest. More or less are all the same like this: `Brenne\BaseBundle\Entity\Company The association Brenne\BaseBundle\Entity\Company#status refers to the owning side field Brenne\BaseBundle\Entity\Websites#website which does not exist.` – s1x Jan 29 '14 at 20:56
  • probably problem in it – Victor Bocharsky Jan 29 '14 at 20:57
  • 1
    You need `mappedBy: company` in your `Company` mapping and `inversedBy: website` in your `Website` mapping. owning and inverse side are concepts of doctrine and might not always reflect what comes to your mind if you think like Company owns website or other way around ... `inversedBy` is always the owning side. – Nicolai Fröhlich Jan 29 '14 at 23:39
  • Yea exactly. I did find that by myself after reading the Doctrine documentation and fixxed it. You're completely right regarding mappedBy/inveresdBy. For ref: http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html – s1x Jan 30 '14 at 01:01
0

If this is really the content of your Websites.orm.yml file, then the indentation is wrong:

You should indent right after Brenne\BaseBundle\Entity\Websites: like so:

Brenne\BaseBundle\Entity\Websites:
    type: entity
    table: websites
    repositoryClass: Brenne\BaseBundle\Repository\WebsitesRepository
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 110
            nullable: true
        url:
            type: string
            length: 255
            nullable: true
        url:
            type: string
            length: 255
            nullable: true
        description:
            type: text
    manyToOne:
        company:
            targetEntity: Company
            inversedBy: websites
            joinColumn:
                name: company_id
                referencedCo
Jasper N. Brouwer
  • 21,517
  • 4
  • 52
  • 76
  • Hey, no the indentation was there. I just struggle a bit with the stackoverflow editor there. As mentioned on the other answer I had some entities errors which I fixed now. I edited the correct Website.orm.yml back into the first question. Thanks for your time! – s1x Jan 29 '14 at 23:08