Ever since we upgrade into Axon.ivy 5.1.x, there are a lot of WARN in the log files:

16:47:08 WARN [runtimelog.alag_bpmp.alag_integration.persistence] [pool-2-thread-302] [requestId=171088, request=, executionContext=SYSTEM] 
  Open entity manager 'org.hibernate.ejb.EntityManagerImpl@3442bb05' detected. Entity manager will be closed now.

Could you explain under what circumstance Axon.ivy write this WARN message? What does it mean?

P.S: In our project, we use JPA EntityManager to maintain transaction by obtaining it from IIvyEntityManager.


asked 29.07.2015 at 04:11

Genzer%20Hawker's gravatar image

Genzer Hawker
accept rate: 66%

edited 02.09.2015 at 15:41

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦

When you create a hibernate EntityManager you should also close its instance when the EntityManager is no longer used. This must be done as else every EntityManager will hold and keep a connection from the connection pool and this can lead to a leak.

To prevent a connection leak the ivy core now closes all open EntityManager instances on HttpRequestEnd. If a not correctly closed instance is found, we log the warning you mentioned.

To avoid the warning you should correctly close open EntityManager instances. Best practice is to handle EntityManager.close() in a finally block:

private static List querySomething(){
    IIvyEntityManager ivyEntityManager = Ivy.persistence().get("myPersistencUnitName");
    EntityManager em = ivyEntityManager.createEntityManager();
        List results = em.createQuery("SELECT XXX").getResultList();
        return results;
    } finally {

answered 29.07.2015 at 11:03

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
accept rate: 70%

edited 29.07.2015 at 12:11

Hello Reguel,

What is happening in finally{ em.close() }

Let's say I encapsulate some methods like this example in some repository class. I`m calling these methods a lot of times.

What is happening in Ivy ? Is the connection to the database opening and closing every time ?

Best Regards, Yordan

(06.02.2017 at 15:00) Stelt0 Stelt0's gravatar image

All connections to external Databases are pooled. So normally no new connection is established but an existing connection from the pool is taken.

I'd expect that if you call these method multiple times, the queries are fired every time against the database layer. So it's a good idea to store and re-use the returned data.

I recommend the usage of our Visual-VM plugin to track the queries that are really sent to the database. In the external DB tab you can see every query that is fired against the DB: http://developer.axonivy.com/doc/latest/EngineGuideHtml/monitoring.html#d5e5101

(06.02.2017 at 16:31) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 29.07.2015 at 04:11

Seen: 4,442 times

Last updated: 06.02.2017 at 16:31