Closed mklueh closed 1 year ago
/cc @DavideD (hibernate-reactive), @Sanne (hibernate-reactive), @gavinking (hibernate-reactive)
The most elementary question is whether or not the Uni
is being subscribed to, because as I'm sure you aware, Uni
is lazy, so if not subscription exists, nothing happens.
Remember a "persist" is just making the object's state to become persisted. The actual insert operation on the DB happens either when the session is flushed or when the transaction is committed.
@geoand thanks. I guess it is subscribed as expected, otherwise, I'd assume there were none of the log outputs either that are part of the stream.
@Sanne I'm just using the reactive PanacheRepository and then just call "persist", with no additional transactions. I'm trying to use persistAndFlush later, in case this makes a difference, but I see no point why it won't get flushed right away or why the transaction would stay open forever even after the REST response has happened. Am I missing something?
Forgot to mention, it's by the way not the only method in my code where the persist is not working.
I guess it is subscribed as expected, otherwise, I'd assume there were none of the log outputs either that are part of the stream.
That is correct. I had not seem the specific line in the logs, hence my question
@mklueh transaction boundaries need to be controlled explicitly.
See:
@Sanne thanks, will try that later and keep you up to date👍
Wouldn't calling persist with no explicit transaction be a valid error case that should throw an exception or is there any use case to it?
Is this behavior related to Quarkus Reactive only? In Spring for example I don't need a transaction at all to persist via repo.
It's a good question; I believe that if you were tro try it with the non-reactive Hibernate ORM you'd get an exception, reminding of the transactional requirement; however in that case we bind to the regular Transaction Manager, which isn't an option for Hibernate Reactive as the TMX APIs are not reactive-friendly: so patterns might diverge a little bit as XA transactions (transactions on multiple resources) aren't available to Hibernate Reactive - this also implies the necessity of sometimes needing to run an operation outside of a transaction scope.
There very rarely might be a use case for doing a non-transactional operation; we might want to enforce the need for a transaction also on Hibernate Reactive, but before doing that we might need some more experience with it - it's still a relatively new technology and "best practices" aren't fully defined yet.
There very rarely might be a use case for doing a non-transactional operation
One idea would be to have a blog post explaining our thinking. It would come in handy in a lot of cases where we could point folks to it
There very rarely might be a use case for doing a non-transactional operation
One idea would be to have a blog post explaining our thinking. It would come in handy in a lot of cases where we could point folks to it
I agree, but I'd rather let power-users explore and define best practices .. it's not like I had much experience with it myself yet. We could enforce the transactions - that would align it with the blocking ORM semantics, and in case I'm missing something that would trigger power users to come forward with their use cases.
but I'd rather let power-users explore and define best practices
What about non-power users though that look to us for suggestions?
but I'd rather let power-users explore and define best practices
What about non-power users though that look to us for suggestions?
Always use transactions, like we do in all examples.
Now that's a good blog post title :)
Works with transactions. Thanks for helping me out.
A blog post would be nice, but a short log message hint would have been even nicer in this regard, esp when it's different from the expected behavior :)
Describe the bug
I'm facing an odd behavior trying to persist some entities using Hibernate Reactive.
The persist call works without errors and the primary key is attached to the entity, but nothing is persisted to the database and there is no error at all.
Expected behavior
To either fail if something is wrong or store the entity accordingly, but not silently do nothing.
Actual behavior
These are the logs I'm getting for
This related code
The id is assigned by the sequence generator
and the persist call does not persist anything
How to Reproduce?
Not sure if this is related to any config properties, entity setup, reactive dependencies or anything else.
Output of
uname -a
orver
No response
Output of
java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
3.3.1
Build tool (ie. output of
mvnw --version
orgradlew --version
)8.3
Additional information
No response