-->
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.  [ 14 posts ] 
Author Message
 Post subject: Can Hibernate be used with shared databases?
PostPosted: Wed Feb 11, 2004 11:22 am 
Newbie

Joined: Wed Feb 11, 2004 11:11 am
Posts: 5
Can Hibernate be used with shared databases?
How does it behave? At our last integration project we chose Castor only because it has the notion of Long Transaction. Before a Long Transaction ends, Castor "refreshes" the cached object from the persistent storage and compares the user object against the fresh one. This way even if another application separately uses the storage we will still have data consistency.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 11:37 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats a very primitive approach to long transactions and optimistic concurrency. Hibernate uses a single UPDATE statement together with a version check and will throw a StaleObjectException if it has been modified in between. Hibernate has extremely flexible support for long "application transactions".

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: A little further complication
PostPosted: Wed Feb 11, 2004 11:51 am 
Newbie

Joined: Wed Feb 11, 2004 11:11 am
Posts: 5
Thanks fot the prompt reply.
I have to add something on my previous question which states the problem more accurately:
As far as I understand, the hibernate persistent object must contain a serial which is stored in the database.
But, the database is NON MODIFIABLE and concurently managed by NON JAVA (AS400-ACG) applications.
Does it still work?
Thanks twice.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If non modifiable mean no schema update, then a lot of people succeed in using Hibernate on a legacy system (using composite-id for example).

You'll have to be more specific to have a more accurate answer

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 12:50 pm 
Newbie

Joined: Wed Feb 11, 2004 11:11 am
Posts: 5
Ok. I'll Describe the problem entirely:

Most of our important projects are aimed to partially wrap and extend existing legacy applications without impacting on the functionality of the old system. For some very specific reasons we cannot wrap and substitute the entirely working apps.
For example we had to build a java document management system that wrapped 70% of the existing application that is written in ACG on AS400 and DB2. The ACG application must still work because the remaining legacy part (Warehouse Office) shares the data with the wrapped part (Purchases Office).
We could create tables only for the new features that were not existing in the old apps, while keeping the rest of db funtionality identical and completely compatibile with the ACGs.

So, when someone loaded a document that maps to legacy data, modified something and then pressed "Save" we had to be sure that we have modified the latest version of that document., because in the meanwhile some ACG user of the warehouse office could have modified that data.

The problem here is that we still need to take advantage of the persistence engine's cache, that shoud somehow "know" that the data has been changed in the underlaying db. Some kind of invalidation without external trigger. This was possible with castor only because on a "LongTransaction" update it reloaded the object's data from db prior to updating it, throwing an ObjectChangedException if the cache and the reloaded data were different.
This way we could assume that most of the time till the expiration of the cached object only our app would use that data. In the extreme case of conflict the user had to press 'refresh data' and lose her changes to the document while in the cache there would be again fresh data.
While castor is limited on some topics that we consider for future use we are still looking for a viable alternative.

What I was asking it was if there is such a mechanism of using hibernate with caching enabled and shared legacy DBs which are non structurally modifiable.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 4:40 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
See optimistic-lock attribute, looks like it can detect conflict without altering database with version field. But I think you will not break legacy applications, if you will add version field to table too (just test it).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 7:05 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It'll break it since legacy apps, don't update the version column when they update.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:14 pm 
Newbie

Joined: Wed Feb 11, 2004 11:11 am
Posts: 5
baliukas wrote:
See optimistic-lock attribute, looks like it can detect conflict without altering database with version field. But I think you will not break legacy applications, if you will add version field to table too (just test it).


Unfortunately it's impossible, as the legacy apps don's use SQL but native apis to access the data, they do not read records and tables as usually but pointers to data, so a new column could crash the system. Instead I was thinking of creating a new table for every legacy table to put the versionID, and map the object to every pair of tables.
While this resolves the extension problem it still does not resolve the data staleness when data modified externally for the reason stated by emmanuel. Do you thing that we could directly configure / modify in some aspect the persistence engine to fit this requirement?
For example by doing an update in which you put all the fields in the where condition instead of only the id and version? If no records affected=>stale data=>exception. The search performance would be not an issue as usually the databases search first for the first field in the where condition (PK) which is fast, and then for the others.
Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Guys, Juozas is right.

You can use optimistic-lock="all" or optimistic-lock="dirty" and then you don't need a version column.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I always forget that feature

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Arh, me too ... I will tatoo it on my head or something :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
;)


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Thu Feb 12, 2004 2:23 pm 
Newbie

Joined: Wed Feb 11, 2004 11:11 am
Posts: 5
Thanks a lot guys!
This is great, I'll definitely give it a try.

It remains only to make sure that we can implement a fully distributed solution using hibernate + cache in cluster.
Some specific docs or suggestions on this?
Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 5:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You don't need distributed cache (you legacy apps will invalid such a choice)

_________________
Emmanuel


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