• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about transaction isolation? The highest levels of isolation defense from dirty reading.
 
Elhanan Maayan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whats the connectin ,i dont care about dirty read of others,im talking my own dirty writes.
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You get good luck from rubbing the belly of a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic