0 Replies Latest reply on Dec 1, 2002 1:09 AM by Kahli Burke

    Handling changes to CMP bean with existing data

    Kahli Burke Newbie

      I am evaluating/researching the potential use of CMP entity beans for a software project I work on. I have searched through the forums and newsgroups (I haven't purchased the documentation yet) and haven't found any good resources on this topic. Can someone here elaborate on this or point me to some discussion of this?

      My question is about CMP in practical use. When software evolves and a new member needs to be added to a CMP entity bean (which maps to a database table) and there is existing data which cannot be lost, how does the migration happen?

      Of course, we could access the database directly and add a column manually, but my understanding of CMP is that it is supposed to shield you from the actual data store. Is this a place where that ideal falls short? Is this the recommended way to handle these cases or is there some other way that JBoss handles it?

      I tried an experiment which involved deploying an EJB (create table set to true, remove table set to false), then adding a field to the class and the mapping and redeploying. This happened fine but the table was not touched in any way so when I tried to use the bean it understandably failed because the new column didn't exist in the table.

      Now, I understand that manually adjusting the table (or writing something that handles these cases) is a viable option. It seems sort of naughty to me, like violating encapsulation or something. I'm just looking for some advice on best practices.

      Thanks!