aspose file tools
The moose likes JSF and the fly likes Database Schema Updates Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Database Schema Updates" Watch "Database Schema Updates" New topic
Author

Database Schema Updates

Chuck Syp
Greenhorn

Joined: Feb 05, 2010
Posts: 5
I have a JSF application that uses hibernate with a MySql database, and I was wondering what most people do to handle database installation/database changes between versions of an application. I want my web app to handle the changes (if any) to the database on tomcat startup/context startup. I want to release this application to the public, but I don't know what is the best model to do this. Do most people just use a servlet to handle this operation, or maybe a ContextListener? I just wanted to ping everyone and see if there was a best practice.

Thanks in advance!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14491
    
    7

This isn't JSF specific, incidentally.

If you're going to dynamically modify the schema from within a webapp, probably the best way to do it is to have a servlet that runs the mods in its init() method and setup web.xml so that that servlet runs first, before any other servlets. That way no one will attempt to access the database while you're modifying it.

In actual practice, I think a lot of people just run the mods as a request from a standard servlet and make the request right after they restart the server. That's a questionable practice, since stuff like that may take longer than a request processor should be taking, and it does risk concurrent accesses by other users while that's going on. But a lot of people don't care.


Customer surveys are for companies who didn't pay proper attention to begin with.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

As a general rule of thumb, software changes should result in the least amount of database changes if at all possible. While this can lead to poorly named and unused database fields, the risk of changing the database is significantly reduced. Keep in mind, a single database change could halt an entire application if it breaks enough queries.


My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Database Schema Updates
 
Similar Threads
properites file
Best way tol load and access application scoped collections?
RMI: Connection timeout on client
Connection Pooling - Passing your pool to the application
Bean Disscussion