Replies: 3 comments 1 reply
-
/cc @FroMage (panache), @gsmet (hibernate-orm), @loicmathieu (panache), @yrodiere (hibernate-orm) |
Beta Was this translation helpful? Give feedback.
-
You actually must not call "persistent" entities are indeed updated automatically on transaction commit (technically on flush, but the distinction doesn't matter here). If you're serializing your entities instead of using proper DTO ( 🫤 ), that means your entity must be made "persistent" (attached to the session) when you want to update it.
Others will say that they would hate to see their calls to entity setters ignored, if they make such calls. Because ignoring such calls is a recipe for bugs. Really, opinions differ a lot in that area.
I can't. JPA spec contributors could.
I don't have the time to go through the basics of JPA right now, unfortunately. Perhaps someone else does, but if not, you can have a look at this introduction which should cover what you need: https://docs.jboss.org/hibernate/orm/6.5/introduction/html_single/Hibernate_Introduction.html#interacting If you don't care about JPA's features (and complexity), and want something closer to the database, |
Beta Was this translation helpful? Give feedback.
-
@yrodiere Thanks for your explanation. I'm currently working on two projects. One uses Quarkus 3.7.4 and the other uses Quarkus 3.11.1.. In the first project (using Quarkus 3.7.4), when I try to find an entity, it fetches from the database and runs an update on the entity, even though I haven't modified any fields. However, I am not encountering this issue in the second project (using Quarkus 3.11.1). Could you help me understand why this discrepancy occurs and how to resolve the issue in Quarkus 3.7.4? |
Beta Was this translation helpful? Give feedback.
-
I've recently started using Quarkus with Hibernate ORM Panache for saving entities. The
persist
method works fine for saving, but I'm encountering an error saying "detached entity" when trying to update an entity usingpersist
. I'm using the repository pattern and annotating the repository class with@Transactional
, but not the service class.After some research, I found that I don't need to use
persist
for updating; the entity will get updated automatically if it is modified. However, I don't understand this design choice. Most of the time, I fetch entities without the intention of updating them, so I don't see why they should be updated automatically.Could you explain the rationale behind this design and possibly share the proper architecture or approach for handling such scenarios? This would be very helpful.
@StFS #Panache
Beta Was this translation helpful? Give feedback.
All reactions