hibernate - Vaadin JpaContainer

标签 hibernate vaadin

我正在使用这个 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/

相关文章:

java - 带有 Spring 数据的 JPA

sql - Grails顺序不起作用

java - 如何从数据库表中获取数据并将该数据更新到 hibernate 中的另一个表中?我已经在 J​​SP 中完成,但我想在 Hibernate 中完成

css - 在 Vaadin 8.1 元素中忽略版本控制的 'styles.scss.cache' 文件?

spring-boot - Spring RequestMapping 返回自动生成的 vaadin html 页面

ssl - 如何通过端口 8443 上的 https 运行 tomcat7 网络应用程序?

vaadin - 如何将 Vaadin DateField 绑定(bind)到 LocalDateTime

java - 使用可选参数在 HQL 中动态搜索查询?

java - 多个 DAO 实例 = 不好?

java - 在java中将点转换为svg路径/文件