Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anotation "@Enum" was never imported error #380

Closed
pmartelletti opened this issue Apr 24, 2014 · 26 comments
Closed

Anotation "@Enum" was never imported error #380

pmartelletti opened this issue Apr 24, 2014 · 26 comments

Comments

@pmartelletti
Copy link

Hi guys,

I'm having an error trying to serialize an Doctrine Entity. I get the following error:

[Semantical Error] The annotation "@enum" in property Doctrine\ORM\Mapping\ManyToMany::$fetch was never imported. Did you maybe forget to add a "use" statement for this annotation?

The entity has excluded all the properties explicitly, and some are exposed with the @Expose method. Here is the code:

<?php

namespace Aaa\Bundle\CoreBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

use FOS\UserBundle\Model\User as BaseUser;
use Sylius\Bundle\AddressingBundle\Model\AddressInterface;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;


/**
 *
 * @ORM\Entity
 * @ORM\Table(name="aaa_as_user")
 * @ExclusionPolicy("all")
 *
 */
class AsUser extends BaseUser
{
    /**
     * @var integer $id
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @Expose
     */
    protected $id;

    /**
     * @var integer $aaaId
     * @ORM\Column(type="string", length=13, nullable=true)
     */
    protected $aaaId;

    /**
     * @var string $firstName
     * @ORM\Column(type="string", length=255)
     * @Expose
     */
    protected $firstName;

    /**
     * @var string $lastName
     * @ORM\Column(type="string", length=255)
     */
    protected $lastName;

    /**
     * @var DateTime $createdAt
     * @ORM\Column(name="created_at", type="datetime")
     * @Gedmo\Timestampable(on="create")
     * @Expose
     */
    protected $createdAt;
...
}

So, I don't have any ideas what could be wrong. It seems that the doctrine anotations are not being loaded correctly in the anotations I use here.

I've read a similar issue here but it's not a proxy issue so I have no idea how to solve this (as the property that has the ManyToOne is excluded, as you can see in the code above; only the present properties are exposed).

So.. is this a bug? Or I'm missing some config? Any ideas?

Thanks a lot for your help!

@pmartelletti
Copy link
Author

@schmittjoh I'm closing this as this issue seems not to be related with this bundle but with sylius resource bundle, sorry about this!

@PunkHaz4rd
Copy link

Hi,
I'm not using sylius resource bundle, yet I get the error :

[Semantical Error] The annotation "@enum" in property Doctrine\ORM\Mapping\GeneratedValue::$strategy was never imported. Did you maybe forget to add a "use" statement for this annotation?

@stof
Copy link
Contributor

stof commented Sep 1, 2014

@SpadesTheOriginal which version of doctrine/annotations are you using ? @Enum is part of Doctrine annotations itself

@PunkHaz4rd
Copy link

I'm not using doctrine/annotations. That's why I'm confused, yet I have the same error as the OP.

I'm using JMS\Serializer\Annotation

@stof
Copy link
Contributor

stof commented Sep 1, 2014

@SpadesTheOriginal JMSSerializer uses the doctrine/annotations package to parse the annotations

@PunkHaz4rd
Copy link

Do I need to specify "use doctrine\annotations" in my user class then ?

@stof
Copy link
Contributor

stof commented Sep 1, 2014

It is not a class. It is a composer package. I'm asking you which version of this package is used in your project.
composer show -i will tell you

@PunkHaz4rd
Copy link

doctrine/annotations v1.2.0

@stof
Copy link
Contributor

stof commented Sep 1, 2014

then it is really weird

@mickaelandrieu
Copy link

@stof I don't see @enum in documentation but the class exists.
Same issue on my side :/
edit: fixed using jsm/serializer-bundle at 0.13.0 AND getArrayResult() instead of getResult()

@serhiikushch
Copy link

i have same issue

[Semantical Error] The annotation "@enum" in property Doctrine\ORM\Mapping\GeneratedValue::$strategy was never imported. Did you maybe forget to add a "use" statement for this annotation?

and only when using Doctrine\ORM\Tools\Pagination\Paginator;

@solazs
Copy link

solazs commented Sep 5, 2014

I had the same error, the problem was my fault, because after using createQueryBuilder(), I forgot to add ->getQuery()->getResult().
A sane error message would be nice, though.

@coma
Copy link

coma commented Oct 15, 2014

@solazs, you just save me some time wasting!

@neemzy
Copy link

neemzy commented Dec 28, 2014

@solazs Same here, thanks ! +1 for a comprehensive error message :)

@bichotll
Copy link

bichotll commented Jan 2, 2015

@solazs can you write down an example? I'm also in trouble...
I tried some ways, but still...error promped.

I checked composer show -i. And as I just checked I'm using the last of everything :(
doctrine/annotations 1.2.3
jms/serializer 0.16.0
jms/serializer-bundle 0.13.0

@bichotll
Copy link

bichotll commented Jan 2, 2015

(message deleted to avoid confusion)

@bichotll
Copy link

bichotll commented Jan 2, 2015

@solazs never mind. Solved :'p

I was trying to parse an Paginator instance with JMSSearializer (I'm using FOS Rest).

//...on the repo
        $query->orderBy('o.created', 'ASC')
                ->setMaxResults($maxResults)
                ->setFirstResult($firstResult);
        $paginator = new Paginator($query, true);
        try {
            return $paginator;
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }


//...on the fos rest controller
        //Paginator object returned
        $paginatorResult = $em->getRepository('BicEntityBundle:Whatever')->findSearched($what, $firstResult, $nResults);

        return $this->handleView(
                $this->view(
                        //because Paginator class implements IteratorAggregate
                        $paginatorResult->getIterator()->getArrayCopy(), 200
                        )
                //just to create the pagination
                ->setHeader('n_results', count($paginatorResult)));

Hope it helps someone.

@Ziiweb
Copy link

Ziiweb commented Jan 27, 2015

Im still gettig this error:

The annotation '@Enum' in property Doctrine\ORM\Mapping\GeneratedValue::$strategy was never imported. Did you maybe forget to add a 'use' statement for this annotation?

Im just trying to serialize a paginator object:

$paginator = new Paginator($query, $fetchJoinCollection = true);
$serializer = \JMS\Serializer\SerializerBuilder::create()->build();
$jsonContent = $serializer->serialize($paginator, 'json');

These are my composer.json packages installed:

doctrine/annotations v1.2.3 Docblock Annotations Parser

@bichotll
Copy link

You can not parse paginator object straight away (JMSSerializer is not prepared for that), do the following:

$paginatorResult->getIterator()->getArrayCopy()

@alainhl
Copy link

alainhl commented Jun 16, 2015

If you are using PagerFanta as your paginator, you must do something like this:

        $objPager->setMaxPerPage(100);
        $objPager->setCurrentPage(1);
        $objPager->getCurrentPageResults()->getArrayCopy()

@anjalirana
Copy link

@solazs 👍 for saving my time :)

@ATLSAPI
Copy link

ATLSAPI commented Sep 7, 2015

Very helpful guys Thanks!!

@Sabistik
Copy link

Sabistik commented Nov 3, 2015

Hi, i have the same issue but when i use Doctrine\Common\Collections\Criteria to find rows:

[Semantical Error] The annotation "@Enum" in property Doctrine\ORM\Mapping\GeneratedValue::$strategy was never imported. Did you maybe forget to add a "use" statement for this annotation?

When i use

$oItemsRows = $this->getEntityManager()->getRepository('Application\Entity\Item')->findBy(array(), $aOrder, $iLimit);

is serialized right but when i use:

$oCriteria = Criteria::create();
$oCriteria->setMaxResults(2);

$oItemsRows = $this->getEntityManager()->getRepository('Application\Entity\Item')->matching($oCriteria);

i got error... Any suggestion?

Regards

@bichotll
Copy link

bichotll commented Nov 3, 2015

I guess that the object returned is not an array.
Try to convert it to an array, then you'll be able to parse it.

@emilio-dc
Copy link

@solazs solution worked for me 👍

@MaximStrutinskiy
Copy link

@solazs TY man, it's help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests