0

i got something like that

 @Transactional
 public class ListController {

   @PersistenceContext
   EntityManager entityManager;


   @GetMapping("/save/avion")
   public ResponseEntity<String> save() {

        Avion avion = new Avion();
        entityManager.persist(avion);
   }

}

I just want to know name of implementation the Spring use for the EntityManager. But i always obtain something lijke that..

I just tried 4 ways..

    System.out.println("==> " + entityManager.getClass());
    System.out.println("==> " + AopProxyUtils.ultimateTargetClass(entityManager));
    system.out.println("==> " + AopUtils.getTargetClass(entityManager).getName());
    System.out.println("==> " + entityManager.getClass().getCanonicalName());

but i systematically obtain..

    ==> class com.sun.proxy.$Proxy110
    ==> class com.sun.proxy.$Proxy110
    ==> com.sun.proxy.$Proxy110
    ==> com.sun.proxy.$Proxy110

So.. i can i obtain concrete class ?

electrode
  • 205
  • 1
  • 4
  • 16

1 Answers1

0

If the requriement is to obtain the name of the under factory bean , a .toString() on the entityManager bean would give that information.

Both

System.out.println(entityManager);

or

String entityManagerName = entityManager.toString();
System.out.println(entityManagerName);

would print in my test project

Shared EntityManager proxy for target factory [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@4f7d3ab3]

Please go through the article (especially point 5 under section B Annotation processing ) to understand the framework code in detail.

R.G
  • 6,436
  • 3
  • 19
  • 28
  • absolutly correct BUT it returns to me concrete implementation of EntityManagerFactory, and not implementation of EntityManager, so i can't see code of my method persist(). – electrode Aug 10 '20 at 08:54
  • Please go through this [SO Q&A](https://stackoverflow.com/questions/3344299/how-do-i-get-the-underlying-type-of-a-proxy-object-in-java) – R.G Aug 10 '20 at 13:13