Vaadin JPAContainer JDBC Connection Usage

[亡魂溺海] 提交于 2019-12-01 00:01:22
Milan Baran

JPAContainer initialization via:

JPAContainerFactory.make(User.class, "persistenceUnitName"); 

uses one and only one EntitiyManager during whole application life span, even other sessions use the same EntityManager. Also, this EntityManager has open one DB connection and it appears to be busy all the time. This approach is not very optimal and it can be bottleneck for your application performance.

Well, JPAContainer can be initialized via:

JPAContainerFactory.make(User.class, (EntityManager)enityManager); 

in this approach you have to handle when to create new EntityManager (EM). You can create new EM per User/Session or per User/Sesssion and Entity it is up to you. This looks promising but JPAContainer has other bottleneck. JPAContainer use one busy connection per EntityManager. So if you create 100 JPAContainer with its own entityManager your connection pool will contain 100 busy connection and this is a big problem. So, you have to set connection release mode to "after_transaction" this will force JPAContainer to release connection after each query.

persistence.xml

<property name="hibernate.connection.release_mode" value="after_transaction" />

Anyway, these are just trick, which make JPAContainer quite usable, but do not expect magic. JPAContainer has much more other issues

  • do not support lazy loading
  • do not support batch loading, each entry is loaded by one query + one query for each relation
  • if you want to refresh JPAContainer it cycle itself and takes forever to refresh

Look at this post. It's better to use plain JPA or Hibernate namedQuery or CriteriaBuilder with BeanItemContainer. Save changes to database vaadin.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!