aspose file tools*
The moose likes Object Relational Mapping and the fly likes is it possible to obtian the entire persitent object map from the session? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "is it possible to obtian the entire persitent object map from the session?" Watch "is it possible to obtian the entire persitent object map from the session?" New topic
Author

is it possible to obtian the entire persitent object map from the session?

Elhanan Maayan
Ranch Hand

Joined: May 04, 2009
Posts: 113
hi.. is it possible to get the entire object session map from the sesion..

the reason is this, we have an object graph which is loaded then then updated from a legacy database, some object may not be updated, so these objects should be marked for deletion, the only we can do this now, to go over the graph again and manually check what has not been updated by ways of special flags.
so we are asking now is it possible for hibernate to help us by providing access to all the objects that were loaded previosly.

the only way i could thing of would be the use of lifecycle interface or the hibernate event system (which we would have to configure and is rather complex given our current framework).
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1



Well, if you load an object with Hibernate, and all associations are eagar, the entire object graph would be loaded into the Session.

loaded then then updated from a legacy database


Loaded by the legacy system, and updated by the legacy system? So, no Hibernate is running at all?

so we are asking now is it possible for hibernate to help us by providing access to all the objects that were loaded previosly.


Previous to what? The update from the external system? Hmmmm...

If you change your data without using Hibernate, there really isn't any way for Hibernate to know what the data used to be?

-Cameron McKenzie
Elhanan Maayan
Ranch Hand

Joined: May 04, 2009
Posts: 113
ok, let met clarify.

1. obtain new data from legacy system, persist it using hibernate in our system.

2. after a while obtan same dataset from legacy using identifers, and load our own data using hibernate.

3. compare the deltas, add new records and delete records if none were found in the legacy.

the last portion is a bit tricky , becouse essentialy we are running based on the legacy data, and if that data was deleted, we simply won't encounter it.
so we must preform an additional itiration on our own object graph to see which object is "dirty" or not.

stanislav bashkirtsev
Ranch Hand

Joined: Aug 17, 2009
Posts: 75
What about transaction isolation? The highest levels of isolation defense from dirty reading.
Elhanan Maayan
Ranch Hand

Joined: May 04, 2009
Posts: 113
whats the connectin ,i dont care about dirty read of others,im talking my own dirty writes.
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
So you are not using hibernate for the legacy system at all, just for the new db system, correct?
If so, then you do not need to load the whole tree, just compare each object you retrieve from the legacy db using identifiers with what hibernate returns (also using identifiers or some way of uniquely identifying each object).
If you really must walk the tree, then you can do so as long as you keep the session open. Just walking the tree in java will load the tree into a hibernate session, again, as long as it is open.

For example, let's say you have 3 hibernate managed entites, A, B, and C, related as follows:
A has a lazy-loaded bidirectional MTM relationship with B and each of them have a lazy bidirectional OTM-MTO relationship with C. Let's say you can identify A uniquely somehow. Then, simply calling A.getCollectionOfBs will load you all associated B entities and A or B .getCollectionOfCs will load each corresponding collection of Cs. Thus, you have the tree in memory and the open hibernate session. However, in order to do any deltas, you still have to have a way of finding each actual object A B and C which you want to compare with what is coming from the legacy system. It would probably be faster and easier if you could do so without loading the tree into memory and did it at the db/hibernate level on each object directly.
Elhanan Maayan
Ranch Hand

Joined: May 04, 2009
Posts: 113
but see this is the problem,

assume i allready have root a, i obtained the collection of b's and i use the legacy data to retrieve certain instances of b's using from the collection (just using iterators and filtering them, now i have b's the were not updated becouse the legacy did not contain them, these b's should be deleted, but in order to do that, i have to know that they were not touched in the first place and thus deleted them.

now you could say i go the other way around, i iterate all b's and retrieve the data from the legacy, once a b i use is not in the legacy i could delete it, but now i have the opposite problem of new data in legacy code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is it possible to obtian the entire persitent object map from the session?