Mikro-orm Bug: Entity 'undefined' entity was not discovered - mikro-orm

How can i fix this bug
Entity 'undefined' entity was not discovered, please make sure to provide it in 'entities' array when initializing the ORM

I faced the same issue in a nestjs project with mikro-orm.
Using entities array instead of entitiesDirs in the configuration (as mentioned by Martin), and stopping the dev server and deleting the /temp and /dist folders before restarting fixed the issue for me.

Related

Use Symfony 4.4.23 without a Database, Symfony update is causing issues with this

I have an old Symfony website which is using the framework bundle but no database is required for the content. This works fine till 4.4.18 but upgrading to the latest version is giving the following error:
An exception occurred in driver: could not find driver
I haven't modified DATABASE_URL in .env or configured the driver in config/packages/doctrine.yaml. Is there anyway I can simple disable the use of database?
Thanks to the comment from #cerad, removing doctrine-migrations package from composer.json helped with the issue.
As I am not using a Database for the site, this is fine for me.
if your app doesn't use the database the best course of action is to remove the doctrine/doctrine-bundle and/or symfony/orm-pack (if you've installed the orm support via pack)
if that's not an option than set the DATABASE_URL= to nothing (like that, not the empty string), or if you've hit some bug in dbal dsn parsing give it the dummy sqlite until the issue gets resolved DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"

hibernate session is null with hibernate-envers

I am facing a serious problem with hibernate-Enver(auditing). My hibernate-5.0.0-final was working perfactly fine. Now I need to add auditing feature to my entities , so I added the #Audited annotation to my entities. When I deployed it on karaf OSGI. i am getting hibernate session null with the exception :
org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.envers.boot.internal.EnversService]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:184)
at org.hibernate.envers.boot.internal.TypeContributorImpl.contribute(TypeContributorImpl.java:22)
at org.hibernate.boot.internal.MetadataBuilderImpl.applyTypes(MetadataBuilderImpl.java:280)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.populate(EntityManagerFactoryBuilderImpl.java:798)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:187)
at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
at org.hibernate.osgi.OsgiPersistenceProvider.createEntityManagerFactory(OsgiPersistenceProvider.java:78)
I install feature of Hibernate Enver also :
feature:install hibernate-orm
feature:install hibernate-envers
I am stuck with it.. Can anyOne help me out ?
Issue Resoved when Update the Hibernate from Hibernate-5.0.0.Final to Hibernate-5.2.0
helping link: https://hibernate.atlassian.net/browse/HHH-10365

PhpStorm does not recognize Doctrine's default entity manager

I have the following code :
$repo = $this->get('doctrine.orm.default_entity_manager')
->getRepository('Acme:Foo');
For the record, the code is working correctly since I can use $repo, its methods and the resulting entities without a problem.
However PhpStorm highlights the 'doctrine.orm.default_entity_manager' string and gives me the following error:
Missing service
I get the same error in my services files when referencing that particular service. Following that, obviously, autocomplete does not work. I can use the following workaround, of course:
/** #var \Doctrine\ORM\EntityManager $em */
$em = $this->get('doctrine.orm.default_entity_manager');
$em->getRepository('Acme:Foo');
This way I still get a warning but autocompletion works properly. However, I'd rather keep my code clean from this kind of annotation as much as possible, plus I'm almost sure there's an easy fix for that. I have of course cleared my cache multiple times.
How can I fix this?
EDIT: I need to mention I'm using the Symfony2 plugin.
In PhpStorm i accidentally mark directory "var" as "Excluded"
So my "fix" was easy:
right click on directory, "Mark Directory as" -> "Cancel Exclusion"
Using latest stable PHPStorm and Symfony plugin, I had problem with some services because my var/cache/ was in /dev/shm in my vagrant box (while PHPStorm is running on windows).
When I have all files var/cache it should be working well.
I think that it needs var/cache/dev/appDevDebugProjectContainer.xml to be generated, up to date, and accessible.
We did the following to avoid issues like you're describing:
In our services.yml I have defined:
entity_manager:
alias: doctrine.orm.entity_manager
The problem was that obviously the Symfony 2 plugin doesn't recognize some 'standard' services which are usually available.
And now using
$this->get('entity_manager');
isn't showing any issue with an activated Symfony 2 plugin.
We use a very similar approach for other 'general services' like Logger, Mailer etc.
As said in comments. Check in Settings -> Plugins Search Symfony Plugin
Then Install it.

How can I get the Doctrine entity metadata before compiling Symfony container?

In one Symfony bundle I define a compiler pass to preprocess some configuration. Part of that config is based on Doctrine entities, so I need to get the full metadata information for all application entities.
The compiler pass is executed very late (PassConfig::TYPE_BEFORE_REMOVING). I'm using $container->get('doctrine') like this to get the entity metadata:
$em = $container->get('doctrine')->getManagerForClass($entityClass);
$entityMetadata = $em->getMetadataFactory()->getMetadataFor($entityClass);
However, this is causing random failures for some users because of the use of the doctrine service during the Symfony container compilation.
I'd recommend to change your entities addressing. Mainly - create your models with interfaces and make entities implementing them.
Using resolve_target_entities Doctrine will "convert" them to the particular classes.
An example code is here: https://github.com/Sylius/SyliusResourceBundle/blob/master/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php
Just make sure your bundle is registered before DoctrineBundle is registered.
Then - in your whole app - instead of AppBundle::Entity addressing, use FQDN of interface bound to an entity earlier.
I've experimented a bit with compilers and services and it's a very bad idea to base on cross-bundle services under compiling container process... Why? It's not reliable - sometimes it will work as you want, sometimes it will fail as you described.
Thank you all for your comments and ideas. I post an answer to explain how I solved this problem.
Trying to use the Doctrine service in a compiler pass was creating more and more problems for our users (and it was creating other minor issues with other services such as Twig). So this was definitely a bad solution for our needs.
So at the end I decided to change everything. We no longer use a compiler pass to process the configuration and instead we use a regular PHP class called during runtime.
In the dev environment, the configuration is processed for each request. It's a bit slower than before, but we prevent any caching issue. In the prod environment we use Doctrine Cache to process the configuration once. Besides, we've create a cache warmer to create the cached configuration before the first request hits the application.

Installing sfGuard without changing db

I am to integrate sfGuard plugin with existing application. What I want to do is to keep as much code as possible untouched. Any guides? It'd be perfect if I can use actual database schema, or bind it somehow to be used by sfGuard. I know about setting userProfile class but I'm not sure how should I get to it, not to destroy my app.
Greetings
Just install plugin. And try make migrations. doctrine::generate-migrations-diff
php symfony doctrine:generate-migrations-diff
And migrate php symfony doctrine:migrate :
php symfony doctrine:migrate
Check out question: Rebuild model without loss data in MySQL for Symfony

Resources