My problem is that I have configured two document managers like this:
doctrine_mongodb:
document_managers:
video:
connection: video
auto_mapping: true
stats:
connection: stats
auto_mapping: true
connections:
video:
server: mongodb://mongo0:27017,mongo1:27017
options:
connect: true
replicaSet: true
slaveOkay: true
stats:
server: mongodb://mongo2:27017,mongo3:27017
options:
connect: true
replicaSet: true
slaveOkay: true
default_document_manager: video
default_connection: video
default_database: my_database
I have the same name for both databases and when I load my page it seems everything's ok (loading my page I only use the 'video' document manager). However, if I use the 'stats' document manager after, symfony seems going crazy.
I have the document managers injected as services like this:
stats_service:
class: %stats_service.class%
arguments:
- #doctrine_mongodb.odm.stats_document_manager
video_service:
class: %video_service.class%
arguments:
- #doctrine_mongodb.odm.video_document_manager
I don't know why, but it seems like every time I do a query, symfony use one of the connections randomly, not the connection of the document manager injected.
Please, help!
Thanks
Ok. I have solved my problem finally. I had both replica sets with the same name and all the problems came from there.
To solved I changed the name of one of the replica sets and the attribute "replicaSet" of the configuration:
doctrine_mongodb:
document_managers:
video:
connection: video
auto_mapping: true
stats:
connection: stats
auto_mapping: true
connections:
video:
server: mongodb://mongo0:27017,mongo1:27017
options:
connect: true
replicaSet: videoReplicaset
slaveOkay: true
stats:
server: mongodb://mongo2:27017,mongo3:27017
options:
connect: true
replicaSet: statsReplicaset
slaveOkay: true
default_document_manager: video
default_connection: video
default_database: my_database
found an interesting article recommending explicit em setting here
Related
I'm using symfony 3.4 + doctrine + redis by using the composer bundle sncRedisBundle
In my config.yml I enabled doctrine query cache:
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
auto_mapping: false
metadata_cache_driver: redis
query_cache_driver: redis
result_cache_driver: redis # !!!
snc_redis:
clients:
doctrine:
type: predis
alias: doctrine_redis
dsn: "%redis_dsn_doctrine%"
logging: false
options:
connection_persistent: true
doctrine:
query_cache: #!!!!!!!!
#it caches the translation from Doctrine's DQL into SQL.
client: doctrine_redis
namespace: shop_doctrine_query
entity_manager: [default, legacy]
The keys set by doctrine for it's result_cache never expire:
How can I call automatically \Doctrine\ORM\Query::setQueryCacheLifetime or make that cache expire. (Note I don't have access to set redis eviction policies on this server).
I think that Doctrine query cache lifetime aren't configured in the doctrine package nor in the redis package, but in the framework package, where you set your pool of cache.
You should have a look on this issue where a user is asking how to configure RedisCluster with Doctrine Cache. B-Galati answers with a configuration example where it defines lifetime for doctrine result cache.
Could you try something like:
framework:
cache:
pools:
cache.doctrine.orm.default.query: ## I'm not sure of this name
adapter: cache.app
default_lifetime: 25200 # 1 week
Or
framework:
cache:
pools:
doctrine.query_cache_pool:
adapter: cache.app
default_lifetime: 25200 # 1 week
The symfony console cache:pool:list command could help you to identify your pools and the symfony console cache:pool:prune could help you to see if out of date queries are well deleted.
I've migrated spring boot 1.x to spring boot 2 with micrometer for metrics. After which could see the metrics in graphite via statsd. But, i can't see it with the prefix
After that i tried for basic prototype by following Configure micrometer-registry-statsd in spring boot 2. But, can't see metrics with prefix. It is showing from the registry name only
config:
management:
health:
defaults:
enabled: true
metrics:
enable:
example:
remote: true
export:
atlas:
enabled: false
statsd:
enabled: true
host: xx.xxx.xx.xx
port: xxxx
flavour: xxxx
step: 10s
**prefix: abc.xy**
security:
enabled: false
when i tried to print the statsdConfig properties the prefix shows as default value "statsd". After which i set the prefix property in the code too. That too didn't help.
Please share details on how to append the statsd.prefix
Existing questions did not help.
I am still learning Symfony and setting up an existing project. Trying to run doctrine fixtures from my application directory.
./app/console doctrine:fixtures:load --env test
And running this gives me following errors
Error thrown while running command "doctrine:fixtures:load --env test --em default". Message: "The class 'ClientPortal\GenericBundle\Document\Accountant' was not found in the chain configured namespaces _XyzProjectName\CalendarContext\Domain\Model, Integration\GetFeedbackBundle\Model, _XyzProjectName\AccountingProcessContext\Domain\Model, _XyzProjectName\CaseContext\Domain" {"exception":"[object] (Doctrine\Common\Persistence\Mapping\MappingException(code: 0): The class 'ClientPortal\GenericBundle\Document\Accountant' was not found in the chain configured namespaces _XyzProjectName\CalendarContext\Domain\Model, Integration\GetFeedbackBundle\Model, _XyzProjectName\AccountingProcessContext\Domain\Model, _XyzProjectName\CaseContext\Domain at /usr/local/var/www/1800-api/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:22)
And this exception is being thrown when trying to persist object of class
'ClientPortal\GenericBundle\Document\Accountant'
and here is my doctrine in config.yml
doctrine:
dbal:
driver: pdo_pgsql
host: '%database_host%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
mappings:
CalendarBundle:
prefix: '_XyzProjectName\CalendarContext\Domain\Model'
IntegrationGetFeedbackBundle:
prefix: 'Integration\GetFeedbackBundle\Model'
AccountingProcessBundle:
prefix: '_XyzProjectName\AccountingProcessContext\Domain\Model'
CaseBundle:
prefix: '_XyzProjectName\CaseContext\Domain'
GenericBundle:
type: "annotation"
prefix: 'ClientPortal\GenericBundle\Document'
dir: 'src'
is_bundle: false
The snippet which is raising this exception
$account = new ClientPortal\GenericBundle\Document\Accountant();//full namespace added for clarity - also this file lies in the same directory structure.
$account->setSfAccountantId($accountantId);
$account->setUsername($username);
$manager = new ObjectManager;
$manager->persist( $account ); //This throws the above mentioned exception
My thought is, the file ClientPortal\GenericBundle\Document\Accountant.php is being autoloaded as there is no exception thrown at the time of instantion of its object. But, there is something missing with configuration or mapping because of which doctrine does not know how to persist its object.
[Source code][1] Accountant class
GenericBundle(s) registered under AppKernel
new Website\GenericBundle\WebsiteGenericBundle(),
new Admin\GenericBundle\AdminGenericBundle(),
new ClientPortal\GenericBundle\ClientPortalGenericBundle(),
new TaxApp\GenericBundle\TaxAppGenericBundle(),
So, as I suggested in comments - try to add ClientPortal\GenericBundle\Document\ namespace to mappings in your doctrine config file, like that:
#...
orm:
auto_generate_proxy_classes: "%kernel.debug%"
mappings:
# ...
ClientPortalGenericBundle:
type: annotation
prefix: 'ClientPortal\GenericBundle\Document\'
dir: '%kernel.root_dir%/src/ClientPortal/GenericBundle/Document/'
#is_bundle: false
auto_mapping: true
Had the same issue with Symfony 4 while using multiple database connections. This one https://stackoverflow.com/a/55361742/2540699 helped me to solved my problem.
I bumped into this kind of message in my Symfony 6.1 project, using multiple entity managers, with one of the entity managers specified as default in doctrine.yaml:
doctrine:
orm:
default_entity_manager: general
entity_managers:
general:
# config for general
other_entity_manager:
# config for other entity manager
Everything was fine on my dev environment, but on production I got the error
Uncaught PHP Exception Doctrine\Persistence\Mapping\MappingException: "The class XXX was not found in the chain configured namespaces " at /opt/approot/current/vendor/doctrine/persistence/src/Persistence/Mapping/MappingException.php
Problem seemed to be that I have a when#prod: section in my doctrine.config.yml. It seems I had to repeat the default_entity_manager over there:
when#prod:
doctrine:
orm:
default_entity_manager: general
# other prod-specific configuration
This fixed it for me.
Update: This is probably related to this issue: https://github.com/symfony/symfony/issues/27769
I have multiple managers and configuration of one of them is like this
doctrine:
orm:
entity_managers:
support:
connection: support
mappings:
APIBundle: ~
But there are tens of entities in APIBundle and I need only some of them in this manager. What a correct configuration should be in such case?
I can't find anything in the doctrine documentation which match with what you're asking.
But by reading the mapping part, we can imagine a little trick to pass through that :
Define your entities in two distinct folders :
APIBundle
|
--- Em1Entity
|
--- SupportEntity
Then in your config, specify the dir configuration :
doctrine:
orm:
entity_managers:
support:
connection: support
mappings:
Support:
mapping: true
type: ~
dir: APIBundle\SupportEntity
alias: ~
prefix: ~
is_bundle: ~
It's just a guess, I didn't personnaly tested this hack.
I am using JMSPaymentCoreBundle and JMSPaymentPaypalBundle.
It worked well before,but now I have to change my config.yml for new Bundle(FOSMessageBundle)
I have to stop using 'auto_mapping' and use 'entity_managers' instead
doctrine:
dbal:
orm:
auto_generate_proxy_classes: %kernel.debug%
# auto_mapping: true
entity_managers:
FOSUserBundle: ~
FOSMessageBundle: ~
However after this changes .
The service "payment.plugin_controller" has a dependency on a non-existent service "doctrine.orm.default_entity_manager"
this error happens.
I think changes in config.yml causes this trouble.
How can I solve this problem?
According to the error, you need to define an entity manager named default. In your case, the overall syntax is just wrong, see my example.
In config.yml:
doctrine:
orm:
entity_managers:
default: # that's the name of the entity manager
connection: default # you need to define the default connection
mappings:
FOSUserBundle: ~
FOSMessageBundle: ~
I'd advise you to read the documentations about "Databases and Doctrine" and "How to work with Multiple Entity Managers and Connections"