gpt4 book ai didi

spring - 在dbcp + spring + hibernate + jdbc中禁用准备好的语句?

转载 作者:行者123 更新时间:2023-12-04 16:08:50 25 4
gpt4 key购买 nike

我目前正在增强一个使用spring和hibernate的应用程序。在多个实例中,该应用程序通过准备好的语句与db(postgres)通信。
到目前为止,该应用程序已通过dbcp与postgres进行了通信。

改变:
现在,该应用程序通过pgbouncer与postgres进行了通信。

即:应用程序-> dbcp-> pgbouncer-> postgres

我知道这不是最理想的解决方案,即:拥有2个池池。但是由于当前的体系结构,我们需要两者。

要求:
pgbouncer不支持事务模式下的准备好的语句,因此必须删除。

更改以消除准备好的语句。

1)psql:版本= 9.2.6

不用找了

2)pgbouncer:在配置文件中设置以下属性

  ignore_startup_parameters=extra_float_digits
pool_mode=transaction
server_reset_query=

3)jdbc:已相应设置了准备的阈值。
即: jdbc:postgresql://localhost:6541/postgres?prepareThreshold=0
 JAVA VERSION = 1.7.0_51

JDBC DRIVER = postgresql-9.3-1102.jdbc41-3.jar

4)dbcp:
poolPreparedStatements = false
maxOpenPreparedStatements = 0

5) hibernate :无变化

6) Spring :无变化

问题:

尽管进行了所有这些更改,我仍然看到尝试创建准备好的语句,并且由于该原因事务失败。

“错误:准备好的语句“S_21”不存在;嵌套的异常是org.postgresql.util.PSQLException:错误:准备好的语句“S_21”不存在”

我已经删除了使用准备好的语句的所有逻辑更改。

如何防止其他准备好的语句被创建?
spring或hibernate是否在内部创建准备使用的语句以供使用?如果是,如何禁用它们?

最佳答案

我知道这篇文章是几年前的,但我仍然面临着同样的问题。不幸的是,建议的更改不适用于当前的用例。

面临以下问题:
-“错误:预准备语句xxx不存在”
-“错误:准备好的语句xxx已经存在”

尝试按照建议的更改进行操作,但仍然收到相同的错误:

技术栈:

  • Spring Boot(2.1.7.RELEASE)
  • Spring数据(JPA + Hibernate)
  • 使用Heroku Postgre
  • 将应用程序部署在Heorku上
  • 客户端PgBouncer。
  • 使用以下属性修改了数据库URL:“?sslmode = disable&prepareThreshold = 0&preparedStatementCacheQueries = 0”
  • 以下设置已添加到Heroku配置中:
  • PGSSLMODE =禁用
  • PGBOUNCER_POOL_MODE =交易
  • PGBOUNCER_IGNORE_STARTUP_PARAMETERS = extra_float_digits
  • 将PGBOUNCER_URLS配置值设置为数据库名称Urls
  • 将Spring Data设置为使用两个数据库进行(读/写和读)。
  • 将@Transactional(readOnly = true)与@Around("@annotation(transactional)")
    public Object proceed(ProceedingJoinPoint proceedingJoinPoint, Transactional transactional) throws Throwable {
    try {
    if(transactional.readOnly()) {
    RoutingDataSource.setReplicaRoute();
    LOGGER.info("Routing database call to the read replica");
    }
    return proceedingJoinPoint.proceed();
    } finally {
    RoutingDataSource.clearReplicaRoute();
    }
    }
    一起使用
  • 关于spring - 在dbcp + spring + hibernate + jdbc中禁用准备好的语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28510587/

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