• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database Schema Updates

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic