• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database Schema Updates  RSS feed

 
Chuck Syp
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 18720
72
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Scott Selikoff
author
Bartender
Posts: 4093
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!