-->
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.  [ 4 posts ] 
Author Message
 Post subject: What exactly constitutes a detached object
PostPosted: Fri Apr 01, 2005 2:42 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0

Mapping documents:General Question


While investigating how we would introduce hibernate persistence in our 3 tier application we are faced with a possible issue/dilemma.

System is thick client and application server/servlet. Swing on the client and business logic processing and persistance will be on server. This is a current running system with legacy persistance.

Our persistant business objects are well defined. They are distributed. That is to say our business object is delivered to the client via SOAP/XML and the objects are reconstituted into java and the client works with them

Scenario
The question is this using a simple single class business object, called Employee (for example).


Server: An instance of Employee is gotten from the DB, assume it has an ID of 100.

Client receives an instance of Employee through SOAP/XML. Client then changes the wages.

Server receives updated instance of Employee from client. ID 100, with new wages.

Now, the question is this. How do we get the changes to the database.

What we would like to do is ask the persistence layer to accept the changed object that we received from the client and update the database. Can this new instance that was provided to the server with just the changes be considered a detached object? It is not technically the exact same objects that were in the session when the session was closed. Can a new session be opened and can this instance of Employee be attached/synchronized to the new session and updated?


Or, are we faced with some way coding our own synchronization between the copy of the object sent to the client for update and the copy we started with on the server? I hope not, since we would be forced to do essentially what we were hoping to use the ORM for.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 3:00 pm 
Newbie

Joined: Sat Sep 13, 2003 12:45 am
Posts: 12
Location: Rochester, NY
I have a similar application except using EJBs to expose the objects to the client. It will pretty much work like you would hope. You just do a saveOrUpdate and Hibernate figures everything out. Seems almost magical sometimes.

_________________
Jim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 3:09 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 11:45 am
Posts: 46
So, do you deploy hibernate and ejb on each client?

I had thought of that - but was hoping to not have to go the ejb route and to limit the burden on the client. Our domain is quite comprehensive and i worry about the work and overhead of exposing all of it in that way ...


But that is certainly an option - thank you for the suggestion.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 01, 2005 3:44 pm 
Beginner
Beginner

Joined: Tue Jun 29, 2004 3:44 pm
Posts: 43
I'm writing an application that works a similar way.

When objects are sent back to the server the server saves them using the merge() command in Hibernate3 (similar to saveOrUpdate() and saveOrUpdateCopy() in Hib2).

It will work fine as long as you get your mapping files right - especially all the cascades. Hibernate will use the id to determine whether the object has been persisted or is new and will act appropriately. I have been able to abstract persistence to the point that I have a set of MyObjectRepository singleton classes with save(myObject o) and get(String id) methods (and a few more methods for convenience). I can call save(myObject) and it and all of its associated objects are stored (or updated) in the database. None of the server classes outside of my persistence package need to know anything about Hibernate and Hibernate isn't needed on the client at all.

You may find it a little more difficult to get advice about using detached objects since it seems most Hibernate users are writing servlets or EJBs. But it is very possible and very supported.


Also, as a heads up, remember that Hibernate will use its own Collections classes to replace any in your objects. This became a problem for me because XMLEncoder doesn't know how to encode them. I use that because it made things really easy for me (until Hibernate). If you're writing your own object -> xml code, that shouldn't be an issue though.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.