EDIT
The obvious solution is to lock the object (i.e. the string) when loading it to bind the form. This ensures that the lock request reads / binds / writes cleanly, without simultaneously writing in the background. This is not ideal, so you will need to weigh potential performance issues (concurrent recording level).
In addition, considering that you are satisfied with the “latest record successes” in your property subgroups, Hibernate “dynamicUpdate” will seem like the smartest solution if you don’t think about switching ORMs any time soon. It seems strange to me that the JPA does not seem to offer anything that allows you to update only dirty fields and most likely it will be in the future.
Optional (my original answer)
Orthogonally to ensure that the transaction opens when your model loads an object to bind the form. The problem is that the properties of the objects are updated at this point and outside the transaction, which leaves the JPA object in an undefined state.
The obvious answer, as Adrian says in his comment, is to use a traditional transaction filter for each request. This ensures that all operations in the request occur in a single transaction. However, it will definitely use the database connection on every request.
There's a more elegant solution with code here . This method is to lazily create an instance of entitymanager and start a transaction only when necessary (i.e. when the first call to EntityModel.getObject () occurs). If a transaction is open at the end of the request cycle, it is committed. The advantage of this is that the connection to the database has never been wasted.
In the above implementation, the RequestCycle calibration object is used (note that this is slightly different in version 1.5), but the whole implementation is actually quite general, so you can use it (for example) using a gate through the servlet. Filter.
source share