I am trying to get my head around the concept of UOW and how I can implement it in my spring/jpa/hibernate app with DDD. I make my methods transactional, but how do I make sure that all the entities that have been changed in the transaction get persisted? Is it by using cascading collections or is there another way?
Hibernate implements Unit of Work internally. That is, all changes made to persistent entities inside a transaction are persisted automatically (unless you have a transaction with readOnly = true
).
Cascading options are needed to configure transition of graphs of transient or detached entities to persistent state.
See also:
how do I make sure that all the entities that have been changed in the transaction get persisted?
That's default behaviour for the JPA EntityManager.
Read this section of the Java EE 5 tutorial (all the way down to Synchronizing Entity Data to the Database)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With