Symfony2 and Doctrine: The table with name 'blog.post' already exists. - symfony

i working with Symfony2 and Doctrine ORM using MySql.
When i try uo use:
php app/console doctrine:migration:diff
i have this error:
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'blog.post' already exists.
My code in Post.php (i use annotation) is:
namespace Blog\ModelBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Post
*
* #ORM\Table()
* #ORM\Entity
*/
class Post extends Timestampable
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=150)
* #Assert\NotBlank
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="body", type="text")
* #Assert\NotBlank
*/
private $body;
/**
* #var Author
* #ORM\ManyToOne (targetEntity="Author", inversedBy="posts")
* #ORM\JoinColumn (name="author_id", referencedColumnName="id", nullable=false)
* #Assert\NotBlank
*/
private $author;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
* #return Post
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set body
*
* #param string $body
* #return Post
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Get body
*
* #return string
*/
public function getBody()
{
return $this->body;
}
/**
* Set author
*
* #param \Blog\ModelBundle\Entity\Author $author
* #return Post
*/
public function setAuthor(Author $author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return \Blog\ModelBundle\Entity\Author
*/
public function getAuthor()
{
return $this->author;
}
}
I try to define * #ORM\Table(name="Post").
Can you help me with this type of error.
Sorry for my bad english.

Your mapping looks incorrect. The ManyToOne declaration does not need an inversedBy attribute if you're not using a join table. You also do not need to specify the #var since it already knows it's using the entity. Try this:
/**
* #ORM\ManyToOne(targetEntity="Author")
* #ORM\JoinColumn(name="author_id", referencedColumnName="id")
**/
private $author;
One other thing to do is to check that you're not trying to declare the same entity in another bundle, this will also cause the "table already exists" error.
Also, to avoid using full path entity references in the getter and setter, just include the entity in the use statemnets at the top of the class, then you only need write the entity name:
/**
* set Author
*
* #param Author $author
*
* #return Post
/**

Related

not defined as association in doctrine orm validate

i have two entities named UserCode and Question that have relation between question columns and when i run doctrine:schema:validate it s ok
but my problem is when i add
#ORM\Entity(repositoryClass="AppBundle\Repository\UserCodeRepository")
at top of UserCode entity i get this error !!
* The association AppBundle\Entity\UserCode#question refers to the inverse side field AppBundle\Entity\Question#question which is not defined as association.
* The association AppBundle\Entity\UserCode#question refers to the inverse side field AppBundle\Entity\Question#question which does not exist.
Question entity :
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use AppBundle\Entity\UserCode;
/**
* Question
*
* #ORM\Table(name="question")
* #ORM\Entity(repositoryClass="AppBundle\Repository\QuestionRepository")
*/
class Question
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="question", type="text")
* #ORM\OneToMany(targetEntity="AppBundle\Entity\UserCode", mappedBy="question")
*/
private $question;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set question
*
* #param string $question
*
* #return Question
*/
public function setQuestion($question)
{
$this->question = $question;
return $this;
}
/**
* Get question
*
* #return string
*/
public function getQuestion()
{
return $this->question;
}
}
and this is my UserCode entity:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn;
use Symfony\Component\Validator\Constraints as Assert;
/**
* UserCode
*
* #ORM\Table(name="user_code")
* #ORM\Entity(repositoryClass="AppBundle\Repository\UserCodeRepository")
*/
class UserCode
{
/**
* #var int
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\Question", inversedBy="question")
* #ORM\JoinColumn(name="question", referencedColumnName="id")
*/
private $question;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set question
*
* #param \AppBundle\Entity\Question $question
*
* #return UserCode
*/
public function setQuestion(\AppBundle\Entity\Question $question = null)
{
$this->question = $question;
return $this;
}
/**
* Get question
*
* #return \AppBundle\Entity\Question
*/
public function getQuestion()
{
return $this->question;
}
}
remove
#ORM\JoinColumn(name="question", referencedColumnName="id")
from
UserCode entity and
* #var string
*
* #ORM\Column(name="question", type="text")
from question entity
it will work perfectly :)

Symfony 2 doctrine DQL order by two fields

Hi guys i have two objects Point and Subpoint when i got from the repository with custom DQL The point i want to order the Points by field ord and the Subpoints to field ord.
Here is the Entities:
namespace George\ArchitectureBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
/**
* Point
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="George\ArchitectureBundle\Entity\PointRepository")
* #Vich\Uploadable
*/
class Point
{
use Translatable;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var Object
* #Gedmo\SortableGroup
* #ORM\ManyToOne(targetEntity="George\ObjectsBundle\Entity\Object", inversedBy="architecturespoints")
* #ORM\JoinColumn(name="object_id", referencedColumnName="id")
*/
private $object;
/**
* #ORM\OneToMany(targetEntity="George\ArchitectureBundle\Entity\Subpoint", mappedBy="point")
*/
private $subpoints;
/**
* #var integer
* #Gedmo\SortablePosition
* #ORM\Column(name="ord", type="integer")
*/
private $ord;
/**
* #var \DateTime
* #Gedmo\Timestampable(on="update")
* #ORM\Column(name="updated", type="datetime")
*/
private $updated;
/**
* #var \DateTime
* #Gedmo\Timestampable(on="create")
* #ORM\Column(name="created", type="datetime")
*/
private $created;
public function __construct()
{
$this->subpoints = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* #return Object
*/
public function getObject()
{
return $this->object;
}
/**
* #param Object $object
*/
public function setObject($object)
{
$this->object = $object;
}
/**
* #return int
*/
public function getOrd()
{
return $this->ord;
}
/**
* #param int $ord
*/
public function setOrd($ord)
{
$this->ord = $ord;
}
/**
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* #return mixed
*/
public function getSubpoints()
{
return $this->subpoints;
}
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* #Vich\UploadableField(mapping="point_image", fileNameProperty="imageName")
*
* #var File
*/
private $imageFile;
/**
* #ORM\Column(type="string", length=255, nullable=true)
*
* #var string
*/
private $imageName;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* #param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
// $this->setModefied(new \DateTime('now')) ;
}
}
/**
* #return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* #param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* #return string
*/
public function getImageName()
{
return $this->imageName;
}
}
Subpoint:
namespace George\ArchitectureBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
use Gedmo\Mapping\Annotation as Gedmo;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
/**
* Subpoint
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="George\ArchitectureBundle\Entity\SubpointRepository")
* #Vich\Uploadable
*/
class Subpoint
{
use Translatable;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var Points
* #Gedmo\SortableGroup
* #ORM\ManyToOne(targetEntity="George\ArchitectureBundle\Entity\Point", inversedBy="subpoints")
*/
private $point;
/**
* #var integer
* #Gedmo\SortablePosition
* #ORM\Column(name="ord", type="integer")
*/
private $ord;
/**
* #var \DateTime
* #Gedmo\Timestampable(on="update")
* #ORM\Column(name="updated", type="datetime")
*/
private $updated;
/**
* #var \DateTime
* #Gedmo\Timestampable(on="create")
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* #return Points
*/
public function getPoint()
{
return $this->point;
}
/**
* #param Points $point
*/
public function setPoint($point)
{
$this->point = $point;
}
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* #Vich\UploadableField(mapping="point_image", fileNameProperty="imageName")
*
* #var File
*/
private $imageFile;
/**
* #ORM\Column(type="string", length=255, nullable=true)
*
* #var string
*/
private $imageName;
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* #param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
// $this->setModefied(new \DateTime('now')) ;
}
}
/**
* #return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* #param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* #return string
*/
public function getImageName()
{
return $this->imageName;
}
/**
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* #return int
*/
public function getOrd()
{
return $this->ord;
}
/**
* #param int $ord
*/
public function setOrd($ord)
{
$this->ord = $ord;
}
}
Repository Point and here i want when i got the Point to be oredered by ord and the subpoints to be ordered by ord:
namespace George\ArchitectureBundle\Entity;
/**
* PointRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class PointRepository extends \Doctrine\ORM\EntityRepository
{
public function getPointsByObject($object)
{
$em = $this->getEntityManager();
$query = $em->createQuery("SELECT p FROM George\ArchitectureBundle\Entity\Point p WHERE p.object =".$object." ORDER BY p.ord ASC");
return $query->getResult();
}
}
But when i put in the creatQuery in Point repository
"SELECT p FROM George\ArchitectureBundle\Entity\Point p WHERE p.object =".$object." ORDER BY p.ord ASC, p.subpoints.ord ASC "
I got error:
[Semantical Error] line 0, col 107 near 'ord ASC ': Error: Class George\ArchitectureBundle\Entity\Point has no field or association named subpoints.ord
EDIT
The solution to the problem is this with query builder with guidance of #Yoshi and #Veve:
public function getPointsByObject($object)
{
$em = $this->getEntityManager();
// $query = $em->createQuery("SELECT p FROM George\ArchitectureBundle\Entity\Point p left join George\ArchitectureBundle\Entity\Subpoint s WITH s.point = p WHERE p.object =".$object." ORDER BY p.ord ASC, s.ord ASC");
$qb = $em->createQueryBuilder();
$qb->select('p')
->from('George\ArchitectureBundle\Entity\Point','p')
->where(' p.object =:object')
->leftJoin('George\ArchitectureBundle\Entity\Subpoint', 's', 'WITH', 's.point = p')
->orderBy('p.ord','ASC')
->orderBy('s.ord','ASC');
$qb->setParameters(array(
'object' => $object
));
$query= $qb->getQuery();
return $query->getResult();
}
You have to join the subpoint to order by one of its attributes:
"SELECT p FROM George\ArchitectureBundle\Entity\Point p
JOIN George\ArchitectureBundle\Entity\Subpoint s WITH s.point = p.id
WHERE p.object =".$object."
ORDER BY p.ord ASC, s.ord ASC"
And as Yoshi commented, you should use the queryBuilder and add your parameters with it instead of building your query by hand.

doctrine2 no metadata classes to process

I'm in a deadend and can't seem to find my way out of this apparently simple problem.
I'm working with Symfony2 and trying to create a database table from an Entity that I generated with the generate:doctrine:entity command. But when I run doctrine:schema:create I always get a "No Metadata Classes to process" message like Doctrine can't find my entity.
I checked the database, the namespace, the annotations, tried creating other entities manually instead of by using the generate:doctrine:entity command but I always get the same result.
Here is my entity :
namespace Blogger\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="blog")
*/
class Blog
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="author", type="string", length=100)
*/
private $author;
/**
* #var string
*
* #ORM\Column(name="blog", type="text")
*/
private $blog;
/**
* #var string
*
* #ORM\Column(name="image", type="string", length=20)
*/
private $image;
/**
* #var string
*
* #ORM\Column(name="tags", type="text")
*/
private $tags;
/**
* #var \DateTime
*
* #ORM\Column(name="created", type="datetime")
*/
private $created;
/**
* #var \DateTime
*
* #ORM\Column(name="updated", type="datetime")
*/
private $updated;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
*
* #return Blog
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set author
*
* #param string $author
*
* #return Blog
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set blog
*
* #param string $blog
*
* #return Blog
*/
public function setBlog($blog)
{
$this->blog = $blog;
return $this;
}
/**
* Get blog
*
* #return string
*/
public function getBlog()
{
return $this->blog;
}
/**
* Set image
*
* #param string $image
*
* #return Blog
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* #return string
*/
public function getImage()
{
return $this->image;
}
/**
* Set tags
*
* #param string $tags
*
* #return Blog
*/
public function setTags($tags)
{
$this->tags = $tags;
return $this;
}
/**
* Get tags
*
* #return string
*/
public function getTags()
{
return $this->tags;
}
/**
* Set created
*
* #param \DateTime $created
*
* #return Blog
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param \DateTime $updated
*
* #return Blog
*/
public function setUpdated($updated)
{
$this->updated = $updated;
return $this;
}
/**
* Get updated
*
* #return \DateTime
*/
public function getUpdated()
{
return $this->updated;
}
}
I'm getting out of ideas. I saw other similar questions but none that could help me. If someone knows what to do, I'd love your help ;)
Something weird happened to me when I put my entity class in a directory called Models, so my namespace was:
AppBundle\Models
But it didn't work.
So I removed that folder and create another folder exactly named Entity and it worked.
So try to remove BlogBundle and put your Entity folder right under you Appbundle folder
Most of the time This error come because of entity path issue and cache
run command first
doctrine:cache:clear-metadata
and then try
doctrine:schema:create
I had the same problem. Try to remove Blogger from your namespace:
namespace BlogBundle\Entity;

Symfony Semantical Error as constraints

After typing this command (php app/console generate:doctrine:entities CoreBundle:Post
) by Terminal the error below appears, How can I solve this?
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation
"#Symfony\Component\Validator\Constraints" in property
Blog\CoreBundle\Entity\Post::$body does not exist, or could not be
auto-loaded.
Source Code:
namespace Blog\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Post
*
* #ORM\Table()
* #ORM\Entity
*/
class Post extends Timestamp
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="body", type="text")
*
* #Assert|NotBlank
*/
private $body;
/**
* #var Author
*
* #ORM\ManyToOne(targetEntity="Author", inversedBy="posts")
* #ORM\JoinColumn(name="author_id", referecedColumnName="id", nullable=false)
*/
protected $author;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
* #return Post
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set body
*
* #param string $body
* #return Post
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Get body
*
* #return string
*/
public function getBody()
{
return $this->body;
}
}
I think you have a typo in the #Assert annotation on the $body property. You're using a pipe symbol | instead of a backslash \.

Symfony2 No mapping file found

am working on symfony2 and am geting this error:
No mapping file found named 'Acme.BlogBundle.Entity.Posts.php' for
class 'Acme\BlogBundle\Entity\Posts'. 500 Internal Server Error -
MappingException
I generate Entity php app/console doctrine:generate:entity
Name of entity: AcmeBlogBundle:Post
Format: php
All that i put in Acme:BlogBundle:Entity directory.
This is my Entity Post class with getter and setter methds:
<?php
namespace Acme\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Posts
*/
class Posts
{
/**
* #var integer
*/
private $id;
/**
* #var string
*/
private $title;
/**
* #var string
*/
private $shortText;
/**
* #var string
*/
private $longText;
/**
* #var string
*/
private $author;
/**
* #var \DateTime
*/
private $dateCreated;
/**
* #var \DateTime
*/
private $dateModified;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
* #return Posts
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set shortText
*
* #param string $shortText
* #return Posts
*/
public function setShortText($shortText)
{
$this->shortText = $shortText;
return $this;
}
/**
* Get shortText
*
* #return string
*/
public function getShortText()
{
return $this->shortText;
}
/**
* Set longText
*
* #param string $longText
* #return Posts
*/
public function setLongText($longText)
{
$this->longText = $longText;
return $this;
}
/**
* Get longText
*
* #return string
*/
public function getLongText()
{
return $this->longText;
}
/**
* Set author
*
* #param string $author
* #return Posts
*/
public function setAuthor($author)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* #return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Set dateCreated
*
* #param \DateTime $dateCreated
* #return Posts
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* #return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated;
}
/**
* Set dateModified
*
* #param \DateTime $dateModified
* #return Posts
*/
public function setDateModified($dateModified)
{
$this->dateModified = $dateModified;
return $this;
}
/**
* Get dateModified
*
* #return \DateTime
*/
public function getDateModified()
{
return $this->dateModified;
}
}
In my controller i first set Post Entity after definig namespace of controller.
use Acme\BlogBundle\Entity\Posts;
After that i create method
public function AddAction()
{
// $post = Acme\BlogBundle\Entity\Posts()
$posts = new Posts();
$posts->setTitle('Test Title');
$em = $this->getDoctrine()->getManager();
$em->persist($posts);
$em->flush();
}
Here is and Stack Trace output
[1] Doctrine\Common\Persistence\Mapping\MappingException: No mapping
file found named 'Acme.BlogBundle.Entity.Posts.php' for class
'Acme\BlogBundle\Entity\Posts'.
at n/a
in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php
line 74
at Doctrine\Common\Persistence\Mapping\MappingException::mappingFileNotFound('Acme\BlogBundle\Entity\Posts',
'Acme.BlogBundle.Entity.Posts.php')
in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/DefaultFileLocator.php
line 117
at Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator->findMappingFile('Acme\BlogBundle\Entity\Posts')
in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/PHPDriver.php
line 59
at Doctrine\Common\Persistence\Mapping\Driver\PHPDriver->loadMetadataForClass('Acme\BlogBundle\Entity\Posts',
object(ClassMetadata))
in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php
line 104
at Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass('Acme\BlogBundle\Entity\Posts',
object(ClassMetadata))
in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
line 113
at Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(object(ClassMetadata),
null, false, array())
in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php
line 302
at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('Acme\BlogBundle\Entity\Posts')
in /var/www/html/Symfony/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php
line 205
at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('Acme\BlogBundle\Entity\Posts')
in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php
line 268
at Doctrine\ORM\EntityManager->getClassMetadata('Acme\BlogBundle\Entity\Posts')
in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
line 1580
at Doctrine\ORM\UnitOfWork->doPersist(object(Posts), array('000000000d824498000000009cdc8511' => object(Posts)))
in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php
line 1555
at Doctrine\ORM\UnitOfWork->persist(object(Posts))
in /var/www/html/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php
line 565
at Doctrine\ORM\EntityManager->persist(object(Posts))
in /var/www/html/Symfony/src/Acme/BlogBundle/Controller/DefaultController.php
line 23
at Acme\BlogBundle\Controller\DefaultController->indexAction()
in line
at call_user_func_array(array(object(DefaultController), 'indexAction'), array())
in /var/www/html/Symfony/app/bootstrap.php.cache line 2815
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request),
'1')
in /var/www/html/Symfony/app/bootstrap.php.cache line 2789
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1',
true)
in /var/www/html/Symfony/app/bootstrap.php.cache line 2918
at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request),
'1', true)
in /var/www/html/Symfony/app/bootstrap.php.cache line 2220
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
in /var/www/html/Symfony/web/app_dev.php line 28
Update:
New Entity Test:
<?php
// src/Acme/BlogBundle/Entity/Test.php
namespace Acme\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table()
* #ORM\Entity
*/
class Test
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string
*
* #ORM\Column(name="short_text", type="string", length=255)
*/
private $shortText;
/**
* #var string
*
* #ORM\Column(name="long_text", type="text")
*/
private $longText;
/**
* #var \DateTime
*
* #ORM\Column(name="date_created", type="datetime")
*/
private $dateCreated;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
* #return Test
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set shortText
*
* #param string $shortText
* #return Test
*/
public function setShortText($shortText)
{
$this->shortText = $shortText;
return $this;
}
/**
* Get shortText
*
* #return string
*/
public function getShortText()
{
return $this->shortText;
}
/**
* Set longText
*
* #param string $longText
* #return Test
*/
public function setLongText($longText)
{
$this->longText = $longText;
return $this;
}
/**
* Get longText
*
* #return string
*/
public function getLongText()
{
return $this->longText;
}
/**
* Set dateCreated
*
* #param \DateTime $dateCreated
* #return Test
*/
public function setDateCreated($dateCreated)
{
$this->dateCreated = $dateCreated;
return $this;
}
/**
* Get dateCreated
*
* #return \DateTime
*/
public function getDateCreated()
{
return $this->dateCreated;
}
}
Again the some error
$ php app/console doctrine:generate:entities AcmeBlogBundle
Generating entities for bundle "AcmeBlogBundle"
[RuntimeException]
Bundle "AcmeBlogBundle" does not contain any mapped entities.
doctrine:generate:entities [--path="..."] [--no-backup] name
You should add mapping information for fields. Read more
Like this:
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
I made the mistake of adding a new Entity through console with a mapping type of 'php' instead of my default 'annotations'. Immediately without even touching the generated class my site wouldn't load. It threw this MappingException for my user class.
I removed the new Entity class thinking that would fix it, and everything else I could think of. Then I looked in my app/Resources/config directory. There was a new directory called Doctrine. It contained a mapping file for the Entity that caused the issue. When I removed this directory and file, the Exception was gone.
If you want to use annotations to defining your mapping, just select the option "annotations" when you generate your entity.
Although this question is quite old I don't want to keep a secret how I solved it. It seems that I had an old mapping files reference in the cache because I moved it to another folder. Clearing the cache solved the issue for me.

Resources