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

Transaction doesn't work if there's a call to an additional suspend function #135

Closed
ronzeidman opened this issue Nov 16, 2022 · 5 comments
Labels
question Further information is requested wontfix This will not be worked on

Comments

@ronzeidman
Copy link

				factory.transactionWithFactory { session, _ ->
					val entity = TestEntity(title = Title("should succeed"))
					session.persist(entity)
						.chain(Supplier { session.flush() })
						.replaceWith(entity)
						.awaitSuspending()
					delay(2000)
				}

^ this code breaks, this means that I can't run a transaction and call external suspend function without breaking the code
Is there something I'm missing?
how can I do multiple things in a transaction like - get -> async big calculation -> save

@shouwn shouwn added the question Further information is requested label Nov 17, 2022
@shouwn
Copy link
Member

shouwn commented Nov 17, 2022

Hi @cj848 Could you check this? I don't know much about hibernate reactive

@cj848
Copy link
Collaborator

cj848 commented Nov 18, 2022

https://github.com/hibernate/hibernate-reactive/blob/main/documentation/src/main/asciidoc/reference/introduction.adoc#sessions-and-vertx-contexts
Please refer to the link. In hibernate reactive internal query execution scope, separate parallel execution or execution through another thread is prohibited.
If a separate thread operation is entered within the db operation, hibernate reactive does not allow it at all because it is difficult to maintain a normal session.

Even if your intention is an operation unrelated to db, it seems to be the intention of the framework developer to prevent the possibility of problems.

This part is not something I can do anything about.
I'm sorry I couldn't help.
If you understand, please close the comment.

@cj848 cj848 added the wontfix This will not be worked on label Nov 18, 2022
@cj848
Copy link
Collaborator

cj848 commented Nov 28, 2022

Since there is no reply for a long time, I will close it. If you have further questions, please proceed to a new issue.

@cj848 cj848 closed this as completed Nov 28, 2022
@namjug-kim
Copy link

This is a closed issue, but i have same problem and it was solved by vertx-lang-kotlin-coroutines

factory.transactionWithFactory { session, _ ->
    CoroutineScope(Vertx.currentContext().dispatcher()).launch {
        val entity = TestEntity(title = Title("should succeed"))
        session.persist(entity)
            .chain(Supplier { session.flush() })
            .replaceWith(entity)
            .awaitSuspending()
        delay(2000)
    }
}

https://vertx.io/docs/vertx-lang-kotlin-coroutines/kotlin/

The vertx.dispatcher() returns a coroutine dispatcher that execute coroutines using the Vert.x event loop.

@cj848
Copy link
Collaborator

cj848 commented Dec 27, 2022

wow.. Oh... I guess this is good practice. thanks. I will make it into a document for reference. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants