ColdFusion 9 ORM and changing the name of a table problem

This is not a real problem in the sense that it shouldn't happen, but it is a problem if you are not aware what is actually happening here.

When defining a persistent component one would normal write it like this:

component persistent="true" {
}

However there is a chance that you may want to use the table attribute, to use it like this.

component persistent="true" table="tableName" {
}

Now normally if you don't use the table attribute what actually takes place is that the table is created with the name of the CFC, however it is also possible to give it another name other than the name of the component.

So why is this a problem, well if you have or are using the setting in the Application.cfc to drop and create the database in development. You need to be careful on how this actually works.

The misconception here is that the database will be dropped and recreated, and under normal circumstances that is what appears to happen. The actual problem is that this is not what actually happens, instead the table is dropped and recreated instead.

So if you find yourself changing the table name, just be very aware that the previous table will still appear in the database.



  • Raymond Camden's Gravatar As just an FYI, you said:

    "Now normally if you don't use the table attribute what actually takes place is that the table is created with the name of the CFC, however it is also possible to give it another name other than the name of the component."

    Also note that CF9/Hibernate supports creating a CFC that lets you set the logic to name tables.

    http://help.adobe.com/en_US/ColdFusion/9.0/Develop...

    FYI - your comment UI is a bit sucky on FF/OSX. When I hit enter, everything scrolls down and I have to scroll the browser.
    # Posted By Raymond Camden | 11/7/09 7:28 AM
  • Andrew Scott's Gravatar Ray, yeah I am aware of that method of the naming strategy. Not sure how that has to do with this problem, or gotcha unless it happens with that as well. I have never used the naming strategy in Hibernate, and from what I do know about it I would expect the same problem.

    As for the UI being a little buggy, there isn't much I can do about it until I have finished writing SpringField. This only started happening when FireFox was updated not so long ago, as all this is pure ColdFusion displaying then its either FireFox or ColdFusion. I am betting a combination of the two, since it used to be all ok.</p>
    # Posted By Andrew Scott | 11/7/09 11:57 AM