Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why ProxyConnection can not use batch? #1256

Closed
cdmikechen opened this issue Mar 30, 2022 · 4 comments
Closed

Why ProxyConnection can not use batch? #1256

cdmikechen opened this issue Mar 30, 2022 · 4 comments

Comments

@cdmikechen
Copy link
Contributor

cdmikechen commented Mar 30, 2022

I use quarkus-hibernate-reactive to insert some rows to table, but it seems like that quarkus does not support reactive batch mode at present. I have written some comments in quarkus issue quarkusio/quarkus#16640
So I start to try to start batch session manually.

I tried many ways, and finally succeeded in this way:

    @Inject
    Mutiny.SessionFactory sessionFactory;

    @POST
    @Path("/batch")
    // @ReactiveTransactional
    public Uni<Void> batch() {
        List<Fruit> fruits = new ArrayList<>();
        for (long i = 0, row = 300; i < row; i++) {
            Fruit fruit = new Fruit();
            fruit.id = i + 1;
            fruit.name = "test";
            fruits.add(fruit);
        }

        return sessionFactory.withTransaction(session ->
                        session.setBatchSize(50).persistAll(fruits.toArray())
                );
//        return Fruit.getSession()
//                .chain(session -> session.persistAll(fruits.toArray()));
    }

Fruit is a PanacheEntityBase:

@Entity
public class Fruit extends PanacheEntityBase {

    @Id
    @Column(name = "id")
    public Long id;

    @Column(length = 40, unique = true)
    public String name;

}

But, if I use Panache Session, session can not use batch. So I check hibernate-reactive codes and I found that Panache use ProxyConnection. in ProxyConnection allowBatching can not used and set to false. I try to change false to allowbatching and rebuild jar, I find that hibernate-reactive can perform batch insert correctly.

@Override
public CompletionStage<Void> update(
String sql,
Object[] paramValues,
boolean allowBatching,
Expectation expectation) {
return withConnection( conn -> conn.update( sql, paramValues, false, expectation ) );
}

So I want to know why ProxyConnection can not use batch?

@DavideD
Copy link
Member

DavideD commented Mar 30, 2022

I think it's a mistake and we should pass allowBatching instead

@DavideD
Copy link
Member

DavideD commented Mar 30, 2022

Please, feel free to send a PR

@cdmikechen
Copy link
Contributor Author

@DavideD
Thanks for your reply, I've opened a PR #1257

@DavideD
Copy link
Member

DavideD commented Mar 31, 2022

Rebased and merged.
Thanks a lot @cdmikechen

@DavideD DavideD linked a pull request Mar 31, 2022 that will close this issue
@DavideD DavideD closed this as completed Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants