Hibernate version:
3.1.1
Mapping documents:
Annotactions
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
MySQL 5.0.18
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A
Another best practice/pattern question.
Our application is a web-based application. We load an entity from the database and essentially throw it to the web client (id and version property included) wrapped in a (mostly) identical transfer object. Then, on update, the web client sends us the transfer object back, we reconstruct the entity (detached), and we call update.
I had been told that this was not optimal. What we should be doing (according to this source) was mapping the entity to the transfer object and sending that back to the client (probably not sending back the version property). When we receive an transfer object back from the client, we should first load the entity from the database and then start mapping the transfer object to the entity, essentially calling the setters on the entity object. This would let hibernate decide what has been changed, what to update, and would eliminate having to pass the version property to the client.
To me, however, I detest having to write all of this mapping code, especially when the objects are identical.
What is the recommended way to do this?
|