doctrine2 no metadata classes to process - symfony

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;

Related

Symfony2 Datetime format

I'm trying to add a simple comment entity, with the "postedOn" attribute as a Datetime. Whenever I try to add a comment, I get this error :
Error: Call to undefined method Symfony\Component\Validator\Constraints\DateTime::format() in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php line 53
Any idea ?
Here's the entity code :
<?php
namespace AOFVH\FlyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Comment
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="AOFVH\FlyBundle\Entity\CommentRepository")
*/
class Comment
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="rating", type="integer")
*/
private $rating;
/**
* #ORM\Column(type="datetime", nullable=true)
*/
protected $postedon;
/**
* #var string
*
* #ORM\Column(name="text", type="text")
*/
private $text;
/**
* #var $commenter
*
* #ORM\ManyToOne(targetEntity="AOFVH\UserBundle\Entity\User", inversedBy="comments", cascade={"persist", "merge"})
*/
private $commenter;
/**
* #var $commenter
*
* #ORM\ManyToOne(targetEntity="AOFVH\FlyBundle\Entity\Flight", inversedBy="comments", cascade={"persist", "merge"})
*/
private $flight;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set rating
*
* #param integer $rating
* #return Comment
*/
public function setRating($rating)
{
$this->rating = $rating;
return $this;
}
/**
* Get rating
*
* #return integer
*/
public function getRating()
{
return $this->rating;
}
/**
* Set text
*
* #param string $text
* #return Comment
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
/**
* Get text
*
* #return string
*/
public function getText()
{
return $this->text;
}
/**
* Set commenter
*
* #param \AOFVH\UserBundle\Entity\User $commenter
* #return Comment
*/
public function setCommenter(\AOFVH\UserBundle\Entity\User $commenter = null)
{
$this->commenter = $commenter;
return $this;
}
/**
* Get commenter
*
* #return \AOFVH\UserBundle\Entity\User
*/
public function getCommenter()
{
return $this->commenter;
}
/**
* Set flight
*
* #param \AOFVH\FlyBundle\Entity\Flight $flight
* #return Comment
*/
public function setFlight(\AOFVH\FlyBundle\Entity\Flight $flight = null)
{
$this->flight = $flight;
return $this;
}
/**
* Get flight
*
* #return \AOFVH\FlyBundle\Entity\Flight
*/
public function getFlight()
{
return $this->flight;
}
Here are the postedOn getters and setters
/**
* Set postedon
*
* #param \DateTime $postedon
* #return Comment
*/
public function setPostedon($postedon)
{
$this->postedon = $postedon;
return $this;
}
/**
* Get postedon
*
* #return \DateTime
*/
public function getPostedon()
{
return $this->postedon;
}
}
I think it's your mapping in your entity, you don't use "datetime" doctrine format else your form type will try to generate a date with a string for example but for me "postedOn must always be defined on a new comment.You can update your entity constructor with : $this->setPostedOn(new \Datetime()); or you can use TimestampableTrait

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

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
/**

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.

symfony 2 switching between types of entity schema description (doctrine)

I develop store using SyliusSandbox bundle.
Sylius uses xml files to store ORM schema for entities.
I've copied its xml definitions to my Bundle and use it there.
But for my own entities, I'd like to use annotations. So, basically I need to mix two types of definitions in one bundle.
If I try to persist an entity which is using annotations, I get an error that xml file for this entity was not found:
No mapping file found named
'ShopBundle\Resources\config\doctrine/ProductLocalized.orm.xml' for
class '\ShopBundle\Entity\ProductLocalized'.
My entity looks like this:
<?php
namespace Pixeljets\ShopBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Pixeljets\ShopBundle\Entity\ProductLocalized
*
* #ORM\Table(name="product_localized")
* #ORM\Entity
*/
class ProductLocalized
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Product", inversedBy="localized")
* #ORM\JoinColumn(name="product_id", referencedColumnName="id")
*/
protected $product;
/**
* #var integer $product_id
*
* #ORM\Column(name="product_id", type="integer")
*/
private $product_id;
/**
* #var string $title
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #var string $url
*
* #ORM\Column(name="url", type="string", length=255)
*/
private $url;
/**
* #var string $keywords
*
* #ORM\Column(name="keywords", type="string", length=255, nullable=true)
*/
private $keywords;
/**
* #var string $description
*
* #ORM\Column(name="description", type="string", length=255, nullable=true)
*/
private $description;
/**
* #var string $body
*
* #ORM\Column(name="body", type="text", nullable=true)
*/
private $body;
/**
* #var boolean $published
*
* #ORM\Column(name="published", type="boolean")
*/
private $published;
/**
* #var string $lang
*
* #ORM\Column(name="lang", type="string", length=2)
*/
private $lang;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set product_id
*
* #param integer $productId
* #return ProductLocalized
*/
public function setProductId($productId)
{
$this->product_id = $productId;
return $this;
}
/**
* Get product_id
*
* #return integer
*/
public function getProductId()
{
return $this->product_id;
}
/**
* Set title
*
* #param string $title
* #return ProductLocalized
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set url
*
* #param string $url
* #return ProductLocalized
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* #return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set keywords
*
* #param string $keywords
* #return ProductLocalized
*/
public function setKeywords($keywords)
{
$this->keywords = $keywords;
return $this;
}
/**
* Get keywords
*
* #return string
*/
public function getKeywords()
{
return $this->keywords;
}
/**
* Set description
*
* #param string $description
* #return ProductLocalized
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* #return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set body
*
* #param string $body
* #return ProductLocalized
*/
public function setBody($body)
{
$this->body = $body;
return $this;
}
/**
* Get body
*
* #return string
*/
public function getBody()
{
return $this->body;
}
/**
* Set published
*
* #param boolean $published
* #return ProductLocalized
*/
public function setPublished($published)
{
$this->published = $published;
return $this;
}
/**
* Get published
*
* #return boolean
*/
public function getPublished()
{
return $this->published;
}
/**
* Set lang
*
* #param string $lang
* #return ProductLocalized
*/
public function setLang($lang)
{
$this->lang = $lang;
return $this;
}
/**
* Get lang
*
* #return string
*/
public function getLang()
{
return $this->lang;
}
/**
* Set product
*
* #param Pixeljets\ShopBundle\Entity\Product $product
* #return ProductLocalized
*/
public function setProduct(\Pixeljets\ShopBundle\Entity\Product $product = null)
{
$this->product = $product;
return $this;
}
/**
* Get product
*
* #return Pixeljets\ShopBundle\Entity\Product
*/
public function getProduct()
{
return $this->product;
}
}
?>
How can I 'tell' symfony to use annotation approach for schema?
You cannot mix metadata formats inside of a bundle:
From: http://symfony.com/doc/current/book/doctrine.html
A bundle can accept only one metadata definition format. For example, it's not
possible to mix YAML metadata definitions with annotated PHP entity class definitions.
You will need to use two bundles or stick with one format.
You should think about using Translatable behavior from DoctrineExtensions to make your products support i18n. Should be much easier than creating another entity for that.

MappingException error on production

I'm getting this error on my production environnent: (from prod.log)
[2012-01-30 17:00:51] request.CRITICAL: Doctrine\ORM\Mapping\MappingException: Class Gitek\UdaBundle\Entity\Curso is not a valid entity or mapped super class. (uncaught exception) at /home/uda/shared/vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php line 142 [] []
But in my development environnent everything works fine.
And this is my Curso entity:
<?php
namespace Gitek\UdaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Gitek\UdaBundle\Entity\Curso
*
* #ORM\Table(name="Curso")
* #ORM\HasLifecycleCallbacks
* #ORM\Entity(repositoryClass="Gitek\UdaBundle\Entity\CursoRepository")
*/
class Curso
{
/**
* #var integer $id
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string $nombre
*
* #ORM\Column(name="nombre", type="string", length=255)
*/
private $nombre;
/**
* #var string $version
*
* #ORM\Column(name="version", type="string", length=255, nullable=true)
*/
private $version;
/**
* #var integer $orden
*
* #ORM\Column(name="orden", type="integer", nullable=true, nullable=true)
*/
private $orden;
/**
* #var integer $tiempo
*
* #ORM\Column(name="tiempo", type="integer", nullable=true, nullable=true)
*/
private $tiempo;
/**
* #ORM\OneToMany(targetEntity="Detcurso", mappedBy="curso", cascade={"remove"})
* #ORM\OrderBy({"orden" = "ASC"})
*/
private $detcursos;
/**
* #ORM\OneToMany(targetEntity="Historial", mappedBy="curso", cascade={"remove"})
*/
private $historiales;
/**
* #ORM\Column(type="datetime")
*/
protected $created;
/**
* #ORM\Column(type="datetime")
*/
protected $updated;
public function __construct()
{
$this->detcursos = new \Doctrine\Common\Collections\ArrayCollection();
$this->setCreated(new \DateTime());
$this->setUpdated(new \DateTime());
}
public function __toString()
{
return $this->getNombre();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nombre
*
* #param string $nombre
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
}
/**
* Get nombre
*
* #return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set version
*
* #param string $version
*/
public function setVersion($version)
{
$this->version = $version;
}
/**
* Get version
*
* #return string
*/
public function getVersion()
{
return $this->version;
}
/**
* Set orden
*
* #param integer $orden
*/
public function setOrden($orden)
{
$this->orden = $orden;
}
/**
* Get orden
*
* #return integer
*/
public function getOrden()
{
return $this->orden;
}
/**
* Set created
*
* #param datetime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* Get created
*
* #return datetime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set updated
*
* #param datetime $updated
*/
public function setUpdated($updated)
{
$this->updated = $updated;
}
/**
* Get updated
*
* #return datetime
*/
public function getUpdated()
{
return $this->updated;
}
/**
* Add detcursos
*
* #param Gitek\UdaBundle\Entity\Detcurso $detcursos
*/
public function addDetcurso(\Gitek\UdaBundle\Entity\Detcurso $detcursos)
{
$this->detcursos[] = $detcursos;
}
/**
* Get detcursos
*
* #return Doctrine\Common\Collections\Collection
*/
public function getDetcursos()
{
return $this->detcursos;
}
/**
* Add historiales
*
* #param Gitek\UdaBundle\Entity\Historial $historiales
*/
public function addHistorial(\Gitek\UdaBundle\Entity\Historial $historiales)
{
$this->historiales[] = $historiales;
}
/**
* Get historiales
*
* #return Doctrine\Common\Collections\Collection
*/
public function getHistoriales()
{
return $this->historiales;
}
/**
* Get historial
*
* #return Doctrine\Common\Collections\Collection
*/
public function getHistorial()
{
return $this->historial;
}
/**
* Set tiempo
*
* #param integer $tiempo
*/
public function setTiempo($tiempo)
{
$this->tiempo = $tiempo;
}
/**
* Get tiempo
*
* #return integer
*/
public function getTiempo()
{
return $this->tiempo;
}
}
As I said, in app_dev works correctly.
You can have different metadata cache configurations depending on which environment you are in. For example apc can cause troubles if not correctly refreshed.
Anyway, you will have to warmup your cache in prod environment, like this:
php app/console cache:clear --env=prod
If this still doesn't work, try to change your doctrine cache configuration:
orm:
auto_generate_proxy_classes: false
default_entity_manager: default
entity_managers:
default:
metadata_cache_driver: array
query_cache_driver: array
result_cache_driver: array
This will use the array cache driver, which is refreshed once at every request.
You shouldn't use this in production, but it can help you to understand where you problem comes from.
In my case the problem was solved by changing my servers cache from eAccelerator to APC. Apparently eAccelerator strips all the comments from files which breaks your annotations.

Resources