Matelutex
Matelutex

Reputation: 2210

Disable all JPA Transactions in Spring Boot app

I'd like to disable all JPA transactions in my Spring Boot services to increase performance. My app handles many database operations and to increase performance I'd like to use pgBouncer in my PostgreSQL database in state Statement pooling (https://wiki.postgresql.org/wiki/PgBouncer#Feature_matrix_for_pooling_modes)

Transactions make database operations very slow (probably???).

Is there any possibility to disable all JPA transactions?

My exemplary Repository:

public interface AgreementRepository extends JpaRepository<Agreement, Long> {

    List<Agreement> findByClientIdAndProductIdIn(Long clientId, List<Long> productIds);
}

My pom:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1206-jdbc42</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>26.0-jre</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
            <version>${spring.cloud.starter.zipkin.sleuth}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
            <version>${spring.cloud.starter.zipkin.sleuth}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

    </dependencies>

Maybe should I change default Isolation level to increase performance? My app handles so many databse operations that the whole process is very slow.

Thanks in advance.

Upvotes: 0

Views: 1821

Answers (1)

Simon Martinelli
Simon Martinelli

Reputation: 36133

If you implement a JpaRepository find methods are by default @Transactional(readOnly=true)

According to Vlad Mihalcea's blog, he is a Hibernate committer, this is already performance optimized: https://vladmihalcea.com/spring-read-only-transaction-hibernate-optimization/

So I assume that your problem is not related to transactions.

Upvotes: 1

Related Questions