简体   繁体   English

什么降低了 Hibernate/Oracle 的速度?

[英]What slows down Hibernate/Oracle?

I have a java application running on a Windows server.我有一个在 Windows 服务器上运行的 Java 应用程序。 This application queries an Oracle 10 database through Hibernate.此应用程序通过 Hibernate 查询 Oracle 10 数据库。 I have a query getting back a collection of 215 entities with 6 string fields each .我有一个查询返回 215 个实体的集合,每个实体有 6 个字符串字段。 It takes around 20s to get them back (stat gotten from hibernate stats)大约需要 20 秒才能恢复它们(统计数据来自休眠统计数据)

I got back sql generated by hibernate and ran it through SQLPlus, got between 300-500ms run time.我找回了 hibernate 生成的 sql 并通过 SQLPlus 运行它,运行时间在 300-500 毫秒之间。

I launched H2 console with ojdbc driver (the same used by my app) and connected to my db (from the same computer as my app run to avoid network problems), ran the sql I got from Hibernate several times, I got the same 300-500ms run time as from SQLPlus so I guess my problem comes from Hibernate but I don't know where to look anymore.我使用 ojdbc 驱动程序启动了 H2 控制台(与我的应用程序使用的驱动程序相同)并连接到我的数据库(从与我的应用程序运行的同一台计算机上运行以避免网络问题),多次运行我从 Hibernate 获得的 sql,我得到了相同的 300 -500ms 运行时间从 SQLPlus 开始,所以我想我的问题来自 Hibernate,但我不知道去哪里找了。

The database is on another server but I got <1ms ping to that server so I don't think network is involved.数据库在另一台服务器上,但我对该服务器的 ping 不到 1 毫秒,所以我认为不涉及网络。

My configuration :我的配置:

javax.persistence.jdbc.driver=oracle.jdbc.driver.OracleDriver
javax.persistence.jdbc.url=jdbc:oracle:thin:@xxxxx
javax.persistence.jdbc.user=xxxxx
javax.persistence.jdbc.password=xxxxx
hibernate.ejb.naming_strategy=org.nuiton.jpa.hibernate.OracleCompliantImprovedNamingStrategy
hibernate.dialect=xxxx.MyDialect

hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.use_sql_comments=false
hibernate.format_sql=true
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy

hibernate.c3p0.min_size=3
hibernate.c3p0.max_size=5
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50

hibernate.generate_statistics = false

Naming Strategy : https://gitlab.nuiton.org/retired/nuiton-jpa/blob/develop/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategy.java命名策略: https : //gitlab.nuiton.org/retired/nuiton-jpa/blob/develop/nuiton-jpa-hibernate/src/main/java/org/nuiton/jpa/hibernate/OracleCompliantImprovedNamingStrategy.java

Dialect :方言 :

public class MyDialect extends Oracle10gDialect {

    public MyDialect() {
        super();
        registerColumnType(Types.DOUBLE, "number");
    }

}

My entities look like (with getters and setters) :我的实体看起来像(使用 getter 和 setter):

public abstract class AbstractJpaRequestedArticle extends AbstractJpaEntity implements Serializable {

    private static final long serialVersionUID = 7293079560062973232L;

    public static final String PROPERTY_ID = "id";

    public static final String PROPERTY_QUANTITY = "quantity";

    public static final String PROPERTY_PRIORITY = "priority";

    public static final String PROPERTY_ARTICLE = "article";

    public static final String PROPERTY_REQUESTED_LIST = "requestedList";

    public static final String PROPERTY_DESTINATION_LOCATION = "destinationLocation";

    @Id
    protected String id;

    protected double quantity;

    protected String priority;

    @ManyToOne
    protected Article article;

    @OneToOne
    protected RequestedList requestedList;

    @ManyToOne
    protected Location destinationLocation;

    @PrePersist
    public void prePersist() {
        if (this.id == null) {
            this.id = new JpaEntityIdFactoryResolver().newId(this);
        }
    }

    @Override
    public String getId() {
        return id;
    }

AbstractJpaEntity only defines equals, hashcode and default toString AbstractJpaEntity 只定义了 equals、hashcode 和默认的 toString

Back on my question to provide an answer I long searched for.回到我的问题来提供我长期寻找的答案。

As @AmitNaik pointed out, my problem was coming from the fetch size that was not set and so used the default one (10).正如@AmitNaik 指出的那样,我的问题来自未设置的提取大小,因此使用了默认值 (10)。 I tried to put a different value in hibernate paramter with no luck.我试图在没有运气的情况下在 hibernate 参数中放置一个不同的值。 It appears that on my Hibernate version, that parameter is not taken into account in my entityManagerFactory (why ?).似乎在我的 Hibernate 版本中,我的 entityManagerFactory 中没有考虑该参数(为什么?)。 So I had to set the fetch size on my specific query and that solved my problem (I now am around 600ms in my test case).所以我必须在我的特定查询上设置获取大小,这解决了我的问题(我现在在我的测试用例中大约 600 毫秒)。 As @john16384 stated, I now have to investigate my SQL query but that is another story.正如@john16384 所说,我现在必须调查我的 SQL 查询,但那是另一回事了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM