Debreker
Debreker

Reputation: 206

Symfony production Mapping Exception FOSUserBundle

I have searched on stackoverflow for my problem, but I have not found an answer for my problem.

Currently I'm deploying my symfony project on my Debian server running PHP 5.6.26 following the documentation on the symfony website.

When I executed the command for installing my bundles by running the command composer install --no-dev --optimize-autoloader

I get the following error:

[Doctrine\ORM\Mapping\MappingException] Class "AppBundle\Entity\User" sub class of "FOS\UserBundle\Model\User" is not a valid entity or mapped super class.

I'm not having this error on my development machines (Windows 10 desktop and a Macbook)

Currently I have no clue of what could be wrong. I did switch from annotation to yml later in the project.

My User.php file:

<?php

namespace AppBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;

/**
 * User
 */
class User extends BaseUser
{

    public function __construct()
    {
        parent::__construct();
    }

    protected $id;

    /**
     * @var \AppBundle\Entity\Address
     */
    private $address;


    /**
     * Set address
     *
     * @param \AppBundle\Entity\Address $address
     *
     * @return User
     */
    public function setAddress(\AppBundle\Entity\Address $address = null)
    {
        $this->address = $address;

        return $this;
    }

    /**
     * Get address
     *
     * @return \AppBundle\Entity\Address
     */
    public function getAddress()
    {
        return $this->address;
    }
}

and my User.orm.yml file:

AppBundle\Entity\User:
    type: entity
    table: user
    repositoryClass: AppBundle\Repository\UserRepository
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
    lifecycleCallbacks: {  }

    oneToOne:
      address:
        targetEntity: AppBundle\Entity\Address
        cascade: ["persist", "remove"]

Upvotes: 2

Views: 400

Answers (2)

Debreker
Debreker

Reputation: 206

After seeing the answer of Alvin Bunk, I saw that the folder Resources (in src/AppBundle) was capitalized in his answer. After checking, my folder Resources was not capitalized.

my fix: Capitalize the folder Resources in src/AppBundle/

Upvotes: 1

Alvin Bunk
Alvin Bunk

Reputation: 7764

I'm not 100% certain, but I see a note here that user is a reserved SQL keyword, and you might need to change your src/AppBundle/Resources/config/doctrine/User.orm.yml file like so:

AppBundle\Entity\User:
    type: entity
    table: fos_user

Can you try and see if that works? I'm not certain though - but try it.

Upvotes: 2

Related Questions