How to manually start a transaction on a shared EntityManager in Spring?

You should use TransactionTemplate object to manage transaction imperatively: transactionTemplate.execute( status -> em.createNativeQuery(“TRUNCATE TABLE MyTable”).executeUpdate()); To create TransactionTemplate just use injected PlatformTransactionManager: transactionTemplate = new TransactionTemplate(platformTransactionManager); And if you want to use new transaction just invoke transactionTemplate.setPropagationBehavior( TransactionDefinition.PROPAGATION_REQUIRES_NEW);

How to mock EntityManager? [closed]

I suggest to use Mockito Framework it is very easy to use and understand. @Mock private EntityManager entityManager; If you want to use any method that belongs to entityManager, you should call. Mockito.when(METHOD_EXPECTED_TO_BE_CALLED).thenReturn(AnyObjectoftheReturnType); When you run your test, any call previosly declared in the Mockito.when for the EntityManager will return the value put in the … Read more

Different ways of getting the EntityManager

There are two ways to create EntityManager instances. One way is for SDK applications, and I use this way a lot in unit testing. This is what you have in your example: EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); In Enterprise applications you let the container create them for you and inject them when needed. EntityManager is just … Read more

The EntityManager is closed

My solution. Before doing anything check: if (!$this->entityManager->isOpen()) { $this->entityManager = $this->entityManager->create( $this->entityManager->getConnection(), $this->entityManager->getConfiguration() ); } All entities will be saved. But it is handy for particular class or some cases. If you have some services with injected entitymanager, it still be closed.

What is the difference between LocalContainerEntityManagerFactoryBean and LocalEntityManagerFactoryBean?

Basically JPA specification defines two types of entity managers. They are : i) Application-Managed : Application Managed entity manager means “Entity Managers are created and managed by merely the application ( i.e. our code )” . ii) Container Managed : Container Managed entity manager means “Entity Managers are created and managed by merely the J2EE … Read more

What is the difference between EntityManager.find() and EntityManger.getReference()?

JPA has the concept of an EntityManager, as you know. During your work in the entity manager some objects are loaded from the database, can be modified and afterwards flushed to the database. find() has to return an initialized instance of your object. If it is not already loaded in the EntityManager, it is retrieved … Read more

Symfony2: how to get all entities of one type which are marked with “EDIT” ACL permission?

I don’t believe there’s a default way of doing this. What you could do is to write your own service that adds a Filter to your Doctrine DQL queries. For more info, see: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/filters.html https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/cookbook/dql-custom-walkers.html Hope this helps!

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)