-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Best Practice - Detached and transfer objects
PostPosted: Thu Jul 13, 2006 12:48 pm 
Newbie

Joined: Thu Jan 12, 2006 6:02 pm
Posts: 9
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?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 12:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Why remap it? Just update the domain object when it comes back - the version property controls the success of the update by checking the value automatically for you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.