aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Global Application Data (Best Practices Question) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Global Application Data (Best Practices Question)" Watch "Hibernate Global Application Data (Best Practices Question)" New topic
Author

Hibernate Global Application Data (Best Practices Question)

Caden Whitaker
Greenhorn

Joined: Jan 15, 2009
Posts: 24
We have a website translated in 16 languages

1: The website will get new translations and changes but in a very infrequent basis (say once every 6 weeks)

2: There is no need to hit repeatedly hit the database for the hundreds of thousands of users hitting this website just to get the website text.

3: It makes more sense to simply store all of this text in application memory (on the webserver) and pull it from there and have this application memory periodically check for changes (once every 24 hours)

4: Rather then have the change set to set time (24 hours) I'd rather hibernate routinely check the "last_modified" date of the text it has cached, if it has changed then update


So here's the table in question
application_text
application_text_id (key)
language_id (foriegn key to language table)
application_text_value
last_modified (datetime)

so I would say "get me text id 5 for language 23" and instead of going to the database it would simply return that object from memory.

Now, I can write this up myself. But I'm wondering if you all had any recommendations for best practice in a situation like this.


Any help would be appreciated


xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
I am not sure, whether this is right way to solve this problem but one way i am looking is to place this object in application level scope.

if(getServletContext().getAttribute("VALUE_FROM_DATABASE") ==null) {

// get the value from database and set it to scope
getServletContext().setAttribute("VALUE_FROM_DATABASE", <VALUE FROM DATABASE>); // set the value to application level scope.

} else {
getServletContext().getAttribute("VALUE_FROM_DATABASE")
}

In this way , this value will be available for diffenrent sessions also. so this will reduce your database hits.

Now if you want to change this value after some days like 6 days, then just ovverride this attribute with new value. You can use below logic to find how old this value has been set in scope .

create one more appication level variable like

getServletContext().setAttribute("SAVED_DATE", <CURRENT DATE>);

So, whenever you fetch value from appliction scope, then fetch saved_date also. and compare it saved date is 6 days old than today's date. If yes, then do database operations and set both values again.

Hope this will help you,

Sunil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Global Application Data (Best Practices Question)