Disabling prepared statements in dbcp + spring + hibernate + jdbc?

I am currently improving an application that uses spring and hibernate. There are several instances where the application communicates with db (postgres) using prepared statements. The application has so far communicated with postgres via dbcp.

Edit: The application is now passed to postgres via pgbouncer.

ie: application → dbcp → pgbouncer → postgres

I understand that this would not be the most ideal solution, namely: the presence of 2 machine guns. But due to the current architecture, we demand both of them.

Requirement: pgbouncer does not support prepared statements in transaction mode and therefore must be resolved.

Changes to exclude prepared statement.

1) psql: VERSION = 9.2.6

without changes

2) pgbouncer: the following attributes are set in the configuration file

ignore_startup_parameters=extra_float_digits pool_mode=transaction server_reset_query= 

3) jdbc: Accordingly, the prepared threshold was set. jdbc:postgresql://localhost:6541/postgres?prepareThreshold=0 .: 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) sleep mode: no change

6) spring: no change

Question:

Despite all these changes, I still see prepared statements that are trying to create, and because of this, transactions cannot be completed.

"ERROR: prepared statement" S_21 "does not exist, the nested exception is org.postgresql.util.PSQLException: ERROR: prepared statement" S_21 "does not exist"

I removed all the logical changes that the prepared statement used.

How can I prevent the creation of other prepared statements? Is spring or hibernation internally creating prepared statements for their use? If so, how to disable them?

+6
source share
1 answer

The following ia configuration working on my system without any ERROR: prepared statement "S_21" does not exist; mistakes. Hope this helps:

  • pgBouncer 1.6.1, pool_mode = transaction
  • Added to Hibernate db connection string: prepareThreshold = 0
  • Postgresql-JDBC driver 9.4-1203-jdbc41
  • Disable ready-made instructions in Hibernate 4.x

     <property name="hibernate.cache.use_query_cache">false</property> 
0
source

Source: https://habr.com/ru/post/982472/


All Articles