-->
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: database changes externally
PostPosted: Fri Aug 06, 2004 1:04 pm 
Newbie

Joined: Fri Aug 06, 2004 1:01 pm
Posts: 13
How is hibernate reacting if there is another application that
connects to the database I am using and that updates records.
Does hibernate handle that ? And will I see the changes in my object ?


Top
 Profile  
 
 Post subject: I'll try...
PostPosted: Sat Aug 07, 2004 7:21 pm 
Newbie

Joined: Sat Aug 07, 2004 5:30 pm
Posts: 5
Location: Munich
Hi, I'm a newbie myself, but I'll try to answer anyway from my understanding of the docs, just to see where I get corrected.

1. If you are only interested in the changes to a specific record at a specific point in the code, and you haven't made any changes to that object in your own application, AFAIR you can update the contents of the in-memory object from the database by calling session.refresh( object ) (NOT session.update(...) - that does something else entirely...).

2. If the other application is the one writing to the records, and you are only reading them (not changing them), it depends on how up-to-date your application's knowledge of the records has to be. Hibernate loads the record when it's first accessed in a Session (or when its contents are accessed in the case of a lazily loaded object), and then keeps the object state cached for the duration of that session (i.e. the session is the mandatory first-level-cache). If you need the object to be more up-to-date, you need to call session.refresh... see above. BUT this answer is only correct as long as you don't have any second-level-caches configured for that object ("<cache-use=...") - in this case, the object will be cached longer than the single session.

3. If both the other application and your application are updateing these records, and it's possible both will be trying to update the same record (row) more or less at the same time, and it's not acceptable for any of these changes to get overwritten - then things get more complicated, and you'll have to implement some kind of optimistic locking / versioning scheme (probably in the other application, too). There is some support in Hibernate for that (see chapter 10 in the reference documentation), but I don't have any experience with that, so I can't give you more concrete tips here.

Hope this helps anyway,
=) Phouk


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.