Symfony 5.2 Multiple Entity Managers strange behaviour - doctrine

I'm trying to use multiple entity managers as described here.
Example code in controller where $shop variable holds the name of the manager:
$rp = new RemoteProduct();
$rp->setProducts(array(2000,2001,2002));
$em = $this->getDoctrine()->getManager($shop);
$em->persist($rp);
$em->flush();
$repo = $em->getRepository(RemoteProduct::class, $shop);
$repo->findAll();
Generates queries to both managers. Flush as a transaction in the correct DB, but select queries are executed in the default DB instead. Any ideas?
doctrine:
dbal:
default_connection: shop1
connections:
shop1:
url: '%env(resolve:DATABASE_URL)%'
mapping_types:
enum: string
store2:
url: '%env(resolve:DATABASE_URL_STORE)%'
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: true
default_entity_manager: shop1
entity_managers:
shop1:
connection: shop1
mappings:
shop1:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: shop1
store2:
connection: store2
mappings:
store2:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: store2

It happens that big fat warning at the end of the documentation was ignored by me.
Do not extend repository class from ServiceEntityRepository
In order to fix this situation, extend EntityRepository instead and no longer rely on autowiring:

Related

Unable to Implement Path Parameter Request Validation

I'm attempting to implement an API that does front-line path parameter validation using AWS SAM that will immediately reject calls whose input does not adhere to the rules defined in a SAM Models block.
Despite re-reading the docs and trying countless implementations, I am unable to reject calls that should be rejected. My GetPetFunction still executes when it shouldn't. Any ideas on what I'm doing wrong, looking at the sample from my template below? I do see the model generated on the APIG console with Request Validator set to params-only.
PetApi:
Type: AWS::Serverless::Api
Properties:
Models:
PetModel:
type: object
required:
- pet
- breed
- color
properties:
pet:
type: string
pattern: (dog|cat)
breed:
type: string
pattern: (poodle|tabby|husky)
color:
type: string
GetPetFunction:
Type: AWS::Serverless::Function
Properties:
Events:
ApiCall:
Type: Api
Properties:
Path: /{pet}/{breed}/{color}
Method: get
RestApiId: !Ref PetApi
RequestParameters:
- method.request.path.pet:
Required: true
- method.request.path.breed:
Required: true
- method.request.path.color:
Required: true
RequestModel:
Model: PetModel
Required: true
ValidateParameters: true

Listener "SoftDeleteableListener" was not added to the EventManager. Soft delete works but i can't register softdeleteable filter

I'm having issues with soft delete from "stof/doctrine-extensions-bundle" package. I'm running Symfony 5.4.
SoftDelete functionality actually works fine, but I can't set up the softdeleteable filter.
This is my config/packages/doctrine.yaml file:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
This is my config/packages/stof_doctrine_extensions.yaml file:
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
softdeleteable: true
And, this is part of my config/services.yaml file:
services:
gedmo.listener.softdeleteable:
class: Gedmo\SoftDeleteable\SoftDeleteableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ "#annotation_reader" ] ]
When I try to delete some entity, it works fine, it updates deletedAt field. But, I want to add softdeleteable filter, and that's when the things stop working. I added gedmo.listener.softdeleteable service to services.yaml and filters part to doctrine.yaml, and i get this error:
Listener "SoftDeleteableListener" was not added to the EventManager!
I can't figure out where I'm making a mistake, and there's not a lot of help in docs.
See: https://github.com/doctrine-extensions/DoctrineExtensions/issues/2535
Looks like caused by symfony/doctrine bridge package. Try upgrade to latest 5.4 version.

How to set a default cache lifetime for doctrine in Symfony 4.4? [duplicate]

This question already has answers here:
How to set namespace and item expiration for a symfony5 redis cachepool
(2 answers)
Closed last month.
I would like to set a default cache lifetime / timeout for doctrine caches in my different environments.
php bin/console config:dump-reference doctrine
shows only options to set the lifetime quite deep down in the advanced configuration in the entity manager regions, where I rather would not mess around. I cannot believe that there is no place to set a general value for db result caching.
Is there really no option to set the default timeout for the cache in a config file?
currrent config/test/doctrine.yaml:
doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_provider
query_cache_driver:
type: service
id: doctrine.system_cache_provider
result_cache_driver:
type: service
id: doctrine.result_cache_provider
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.system_cache_pool'
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
I've did it like this...
framework:
cache:
default_memcached_provider: 'memcached://localhost:...'
pools:
doctrine.result_cache_pool:
adapter: cache.adapter.memcached
public: false
default_lifetime: 86400
In config/packages/prod/doctrine.yaml
Need to change to:
doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_pool
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system

Symfony connect to oracle oci8

I'm on Symfony and I can't connect to a Oracle database, but I don't know why. Maybe you can help me a little.
Here my doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
url: '%env(DATABASE_URL)%'
server_version: '5.7'
charset: utf8mb4
test:
# configure these for your database server
url: '%env(DATABASE_TEST_URL)%'
driver: 'oci8'
server_version: ~
charset: utf8mb4
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
test:
connection: test
mappings:
test:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Test'
prefix: 'App\Entity\Test'
alias: Test
My .env file with 2 database:
DATABASE_URL=mysql://xxx:xxx#mysql:3306/pivot
DATABASE_TEST_URL=//user:owd#host:port/dbname
And here my controller
public function xxx() {
$entityManager = $this->getDoctrine()->getConnection('test');
$sql = 'SELECT * FROM xxx.O2_ADRESSE WHERE ROWNUM = 1';
$stmt = $entityManager->prepare($sql);
$stmt->execute();
dump($stmt->fetchAll());
}
I get the following error :
An exception occurred in driver: ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
Any help on what im doing wrong?
Are you sure that the db is running?
You can check it via sqlplus, eg:
sqlplus user:password#mysql:3306/pivot
Can you update DATABASE_URL and try?
to use oracle: DATABASE_URL="oci8://db_user:db_password#127.0.0.1:1521/db_name"
https://symfony.com/doc/current/doctrine.html
https://symfony.com/doc/current/bundles/DoctrineBundle/configuration.html#oracle-db

JHipster test: NoCacheRegionFactoryAvailableException when second level cache is disabled

When I use jhipster generate an app, I disabled the second level cache. However, when I run either "gradle test" or "run as junit test" to test the app, it is failed because the "NoCacheRegionFactoryAvailableException". I have checked the application.yml in directory "src/test/resources/config", and be sure that the second cache is disabled. I do not know why the app is still looking for second-cache. Is there any clue how this happen? or how to disable second level cache completely?
Except the test failure, everything else works well, the app can run successfully.
application.yml in src/test/resources/config
spring:
application:
name: EMS
datasource:
url: jdbc:h2:mem:EMS;DB_CLOSE_DELAY=-1
name:
username:
password:
jpa:
database-platform: com.espion.ems.domain.util.FixedH2Dialect
database: H2
open-in-view: false
show_sql: true
hibernate:
ddl-auto: none
naming-strategy: org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy
properties:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.hbm2ddl.auto: validate
data:
elasticsearch:
cluster-name:
cluster-nodes:
properties:
path:
logs: target/elasticsearch/log
data: target/elasticsearch/data
mail:
host: localhost
mvc:
favicon:
enabled: false
thymeleaf:
mode: XHTML
liquibase:
contexts: test
security:
basic:
enabled: false
server:
port: 10344
address: localhost
jhipster:
async:
corePoolSize: 2
maxPoolSize: 50
queueCapacity: 10000
security:
rememberMe:
# security key (this key should be unique for your application, and kept secret)
key: jhfasdhflasdhfasdkfhasdjkf
metrics: # DropWizard Metrics configuration, used by MetricsConfiguration
jmx.enabled: true
swagger:
title: EMS API
description: EMS API documentation
version: 0.0.1
termsOfServiceUrl:
contactName:
contactUrl:
contactEmail:
license:
licenseUrl:
enabled: false
Move src/test/resources/config/application.yml to src/test/resources directory.
You can find that solution from https://github.com/jhipster/generator-jhipster/issues/3730

Resources