Vaadin JPAContainer JDBC连接用法 [英] Vaadin JPAContainer JDBC Connection Usage

查看:81
本文介绍了Vaadin JPAContainer JDBC连接用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦创建了一个JPAContainer,就像

Once one JPAContainer is created like

JPAContainer users = JPAContainerFactory.make(User.class,persistenceUnitName);

JPAContainer users = JPAContainerFactory.make(User.class, "persistenceUnitName");

现在我假设users容器将使用一个EntityManager,而EntityManager又使用连接池中的一个JDBC连接。

Now I suppose that the "users" container will use one EntityManager which in turn uses one JDBC connection from the connection pool.

该资源利用率(jdbc)附加到JPAContainer的EntityManager的连接)在httprequest的生命周期内发生,或者entityManager / connection的使用还有另一个生命周期?

That resource utilization (jdbc Connection attached to EntityManager attached to JPAContainer) happens during the lifetime of the httprequest or the usage of the entityManager/connection has another lifespan ?

你能帮我理解这个差距吗?一个JPAContainer实例之间以及通过EntityManager何时以及如何使用jdbc连接?

Can you please help me understand the gap between one JPAContainer instance and when and how jdbc connections are used through the EntityManager ?

我阅读了vaadin jpa容器教程,我在那里找不到这些信息。
谢谢。

I read the vaadin jpa container tutorial and I don't find this information there. Thank you.

https://vaadin.com/forum/-/message_boards/view_message/1601953

推荐答案

JPAContainer初始化:

JPAContainer initialization via:

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

在整个应用程序生命周期内使用一个且只有一个EntitiyManager,甚至其他会话也使用相同的EntityManager。此外,此EntityManager已打开一个数据库连接,它似乎一直处于忙碌状态。这种方法不是很优化,它可能是您的应用程序性能的瓶颈。

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.

好吧,JPAContainer可以通过以下方式初始化:

Well, JPAContainer can be initialized via:

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

在此方法中,您必须处理何时创建新的EntityManager(EM)。您可以为每个用户/会话或每个用户/ Sesssion和实体创建新的EM,这取决于您。这看起来很有希望,但JPAContainer还有其他瓶颈。 JPAContainer每个EntityManager使用一个忙连接。因此,如果您使用自己的entityManager创建100 JPAContainer,您的连接池将包含100个忙连接,这是一个大问题。因此,您必须将连接释放模式设置为after_transaction,这将迫使JPAContainer在每次查询后释放连接。

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" />

无论如何,这些只是技巧,这使得JPAContainer非常实用,但不要指望魔术。 JPAContainer还有更多其他问题

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


  • 不支持延迟加载

  • 不支持批量加载,每个条目由一个查询加载+每个关系一个查询

  • 如果你想刷新JPAContainer它自行循环并需要永远刷新

看看这篇文章。最好使用普通的JPA或Hibernate namedQuery或CriteriaBuilder和BeanItemContainer。
保存对数据库vaadin的更改

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

这篇关于Vaadin JPAContainer JDBC连接用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆