gpt4 book ai didi

java - 是什么减慢了 Hibernate/Oracle 的速度?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:10 26 4
gpt4 key购买 nike

我有一个在 Windows 服务器上运行的 Java 应用程序。此应用程序通过 Hibernate 查询 Oracle 10 数据库。我有一个查询返回 215 个实体的集合,每个实体有 6 个字符串字段。大约需要 20 秒才能恢复(从 hibernate 状态中获取的状态)

我取回了由 hibernate 生成的 sql 并通过 SQLPlus 运行它,运行时间在 300-500 毫秒之间。

我使用 ojdbc 驱动程序启动 H2 控制台(与我的应用程序使用的相同)并连接到我的数据库(从与我的应用程序运行相同的计算机以避免网络问题),多次运行我从 Hibernate 获得的 sql,我得到了与 SQLPlus 相同的 300-500 毫秒运行时间,所以我猜我的问题来自 Hibernate,但我不知道该去哪里找了。

数据库在另一台服务器上,但我收到 <1 毫秒的 ping 到该服务器,所以我认为不涉及网络。

我的配置:

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

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

方言:

public class MyDialect extends Oracle10gDialect {

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

}

我的实体看起来像(带有 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 只定义了equals、hashcode 和默认的toString

最佳答案

回到我的问题,提供我长期寻找的答案。

正如@AmitNaik 所指出的,我的问题来自未设置的获取大小,因此使用了默认大小 (10)。我试图在 hibernate 参数中设置不同的值,但没有成功。看来在我的 Hibernate 版本中,我的 entityManagerFactory 中没有考虑该参数(为什么?)。所以我必须在我的特定查询上设置获取大小,这解决了我的问题(我现在在我的测试用例中大约 600 毫秒)。正如 @john16384 所说,我现在必须调查我的 SQL 查询,但那是另一回事了。

关于java - 是什么减慢了 Hibernate/Oracle 的速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56356606/

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