Quarkus Hibernate Orm Panache - Batching -Inserts funktionieren nichtJava

Java-Forum
Anonymous
 Quarkus Hibernate Orm Panache - Batching -Inserts funktionieren nicht

Post by Anonymous »

Ich habe in letzter Zeit einige Volumentests in einer Anwendung durchgeführt, und ich habe festgestellt, dass die Anwendung bei hohen Volumentransaktionen langsam ist. Als ich einige Debugging machte, bemerkte ich, dass die Einsätze nicht angegriffen werden. Ich stieß auf das gleiche Problem auf, einen minimalen Reproduktion von Grund auf zu bauen. /> < /ul>
Testentity.java

Code: Select all

package org.example;

import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import java.util.UUID;

@Entity
@Table(name = "TestEntity", schema = "testdb")
public class TestEntity extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "id")
private UUID id;

@Column(name = "testCol")
private final Integer testCol;

private TestEntity(final Builder builder) {
this.testCol = builder.testCol;
}

protected TestEntity() {
this.id = null;
this.testCol = null;
}

public UUID getId() {
return id;
}

public Integer getTestCol() {
return testCol;
}

public static final class Builder {
private Integer testCol;

public Builder testCol(final Integer testCol) {
this.testCol = testCol;
return this;
}

public TestEntity build() {
return new TestEntity(this);
}
}
}
Testresource.java

Code: Select all

package org.example;

import jakarta.transaction.Transactional;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;

import java.util.ArrayList;
import java.util.List;

@Path("/test")
public class TestResource {

@POST
@Transactional
public Response hello() {
try {

List testEntities = new ArrayList();
for (int i = 0; i < 10; i++) {
testEntities.add(new TestEntity.Builder().testCol(i).build());
}

TestEntityRepository testEntityRepository = new TestEntityRepository();

testEntityRepository.persist(testEntities);

return Response.ok().build();
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}

}
}
TestentityRepository.java

Code: Select all

package org.example;

import io.quarkus.hibernate.orm.panache.PanacheRepository;
import jakarta.enterprise.context.ApplicationScoped;

import java.util.Optional;
import java.util.UUID;

@ApplicationScoped
public class TestEntityRepository implements PanacheRepository {

public Optional  findById(final UUID id) {
return find("id", id).firstResultOptional();
}
}
In der Quarkus -Konsole erhalte ich mehrere identische Einfügungsanweisungen und zeigt deutlich, dass es keine Batching gibt.

Code: Select all

2025-07-02 15:20:59,929 DEBUG [org.hib.eng.jdb.spi.SqlStatementLogger] (executor-thread-2)
insert
into
testdb.TestEntity
(testCol, id)
values
(?, ?)
2025-07-02 15:20:59,930 DEBUG [org.hib.eng.jdb.spi.SqlStatementLogger] (executor-thread-2)
insert
into
testdb.TestEntity
(testCol, id)
values
(?, ?)
2025-07-02 15:20:59,930 DEBUG [org.hib.cac.int.TimestampsCacheEnabledImpl] (executor-thread-2) Pre-invalidating space [testdb.TestEntity], timestamp: 1751462519930
2025-07-02 15:20:59,932 DEBUG [org.hib.eng.jdb.bat.int.BatchImpl] (executor-thread-2) PreparedStatementDetails did not contain PreparedStatement on #releaseStatements : insert into testdb.TestEntity (testCol,id) values (?,?)
2025-07-02 15:20:59,933 DEBUG [org.hib.eng.tra.int.TransactionImpl] (executor-thread-2) On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2025-07-02 15:20:59,933 DEBUG [org.hib.res.jdb.int.LogicalConnectionManagedImpl] (executor-thread-2) Initiating JDBC connection release from beforeTransactionCompletion
2025-07-02 15:20:59,933 DEBUG [org.hib.eng.jdb.bat.int.BatchImpl] (executor-thread-2) PreparedStatementDetails did not contain PreparedStatement on #releaseStatements : insert into testdb.TestEntity (testCol,id) values (?,?)
2025-07-02 15:20:59,946 FINE [org.pos.jdb.PgConnection] (executor-thread-2) setAutoCommit = true
2025-07-02 15:20:59,947 DEBUG [org.hib.eng.jdb.bat.int.BatchImpl] (executor-thread-2) PreparedStatementDetails did not contain PreparedStatement on #releaseStatements : insert into testdb.TestEntity (testCol,id) values (?,?)
2025-07-02 15:20:59,947 DEBUG [org.hib.res.jdb.int.LogicalConnectionManagedImpl] (executor-thread-2) Initiating JDBC connection release from afterTransaction
2025-07-02 15:20:59,947 DEBUG [org.hib.cac.int.TimestampsCacheEnabledImpl] (executor-thread-2) Invalidating space [testdb.TestEntity], timestamp: 1751462459947
2025-07-02 15:20:59,948 DEBUG [org.hib.eng.jdb.int.JdbcCoordinatorImpl] (executor-thread-2) HHH000420: Closing un-released batch
2025-07-02 15:20:59,948 DEBUG [org.hib.eng.jdb.bat.int.BatchImpl] (executor-thread-2) PreparedStatementDetails did not contain PreparedStatement on #releaseStatements : insert into testdb.TestEntity (testCol,id) values (?,?)
2025-07-02 15:20:59,948 DEBUG [org.hib.eng.jdb.bat.int.BatchImpl] (executor-thread-2) PreparedStatementDetails did not contain PreparedStatement on #releaseStatements : insert into testdb.TestEntity (testCol,id) values (?,?)
< /code>
Hier sind einige Anwendungen.quarkus.datasource.jdbc.transactions=enabled
quarkus.transaction-manager.default-transaction-timeout=6000 #high timeout for testing purposes
quarkus.hibernate-orm.jdbc.statement-batch-size=1000
quarkus.hibernate-orm.unsupported-properties."hibernate.order_inserts" = true

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post