Once one JPAContainer is created like
JPAContainer users = JPAContainerFactory.make(User.class, \"persistenceUnitName\");
Now I suppose that the \"users\" co
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
Look at this post. It's better to use plain JPA or Hibernate namedQuery or CriteriaBuilder with BeanItemContainer. Save changes to database vaadin.