gpt4 book ai didi

hibernate - Vaadin JpaContainer

转载 作者:行者123 更新时间:2023-12-02 21:55:28 25 4
gpt4 key购买 nike

我正在使用这个 JPAContainer + Hibernate,它需要很长时间才能加载。例如,带有 SQLContainer 的页面加载 60 毫秒,而带有 JPA 容器的同一页面加载 1.30 秒。

通过控制台中的 JPAContainer,我看到许多 SQL 查询 - 对于每个实体 - 查询;实体Person没有到其他表的链接;

使用 jpacontainer 的代码:

JPAContainer<Person> container = JPAContainerFactory.make(Person.class,
"persistence-unit");
table.setContainerDataSource(container);

使用 SQLContainer 的代码:

JDBCConnectionPool pool = null;
try {
pool = new SimpleJDBCConnectionPool("org.postgresql.Driver",
"jdbc:postgresql://127.0.0.1:5432/postgres", "postgres",
"pwd");
} catch (SQLException e) {
e.printStackTrace();
}
TableQuery tq = new TableQuery("Person", pool);
SQLContainer sqlContainer = null;
try {
sqlContainer = new SQLContainer(tq);
} catch (SQLException e) {
e.printStackTrace();
}
table.setContainerDataSource(sqlContainer);

我的 persistence.xml 文件:

<persistence-unit name="persistence-unit" transaction-type="RESOURCE_LOCAL">

<jta-data-source>java:jboss/datasources/mfc-frontendDS</jta-data-source>

<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
</properties>

我做错了什么?

最佳答案

别再跟JPAContainer争了,它背后有太多抽象层。

enter image description here

SQLContainer 足够好,快速且稳定。我并不是说 SQLContainer 是 JPAContainer 的替代品,但实际价格似乎太高了。从可用性的角度来看,响应能力是一个非常重要的因素,因此最好不要从花在持久层上的开始。

无论如何,如果您确实想继续使用 JPAContainer,有几个可用的选项:

使用 CachingLocalEntityProvider

经验法则:访问速度慢——使用缓存

If the number of database round-trips should be reduced, CachingLocalEntityProvider should be used instead. It maintains a local cache of entities and query results and hence should perform faster than LocalEntityProvider if database round-trips are slow. However, it also requires more memory than LocalEntityProvider.

使用分页 ( PagedTable )

这将大大减少查询数量,因为页面是延迟加载的。

PagedTable is a component that behaves in the same matter as the Vaadin core Table, except that it has multiple pages instead of scrolling to show more entries.

enter image description here

使用 JPAContainer 过滤器

All filtering is done at the database level with queries, not in the container. The filtering implementation uses the JPA 2.0 Criteria API transparently. As the filtering is done at the database-level, custom filters that use the Filterable API do not work.

另请检查:JPAContainer Usage and Performance questions

关于hibernate - Vaadin JpaContainer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13681043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com