In a perfect world of software development where a database is involved the naming conventions for tables and columns are standard. As you are aware that is not always the case. Sometimes we deal with really long or unconventional naming strategies. Fortunately for us hibernate has a way of dealing with this and ColdFusion, like everything else it does has made this really for us to use.
Let's pretend for our demo here that we are doing some work for ABC Company and that have this weird naming strategy where all of there table names are prefixed with tbl_ and all of their column names are prefixed with col_. I think you get the idea. If we were to create an entity based off of this table we would end up writing code that looked like this. The first thing you might be asking yourself is "Why is the name of the entity Person and not tbl_Person"? This because entity names are used in this order.
- The table name for the cfc
- If it is not specified, the entity name is taken as the logical table name
- If the entity name is also not specified, the unqualified CFC name, for example, Person for a.b.c.Person, is taken as the logical table name.
You can see the problem with this, not only does it become a pain to write but lets face it, this is pretty ugly code. We do have a way around this by using some attribues on the component and properties. So remember since we are specifying the table name we need an entity name so we don't have to refer to it in code as tbl_Person. Same with the column names, we are telling the entity the name of the column but the property name is how we will refer to it in the future.
Now this might not look like a lot of work but even for 1 component this is some real useless typing on your part. Now imagine you have 50 tables in your application. Do you really want to go through and map all of your tables and columns? I sure don't and thankfully there is a better solution to this problem. We can create a Naming Strategy for our application. This is a component that implements CFIDE.orm.INamingStrategy. Basically there are two methods in this interface. So here is my naming strategy for our abc company application. All we are doing is prefixing the table and column names and returning the result. To use this naming strategy in our application we have to set it in our orm settings. My Naming Strategy component is in a folder com/abc/ Values for naming strategy can be.
- default: This strategy uses the logical table or column name as it is. ColdFusion ORM using this value as the default strategy.
- smart: This strategy changes the logical table or column name to uppercase. Also, if the logical table or column name is in camel case, this strategy breaks the camelcased name and separates the broken words using underscore. For example, for a CFC named "OrderProduct", this strategy changes the table name as "ORDER_PRODUCT".
- your own cfc : You can get complete control of the naming strategy by providing your own implementation. You need to specify the fully qualified name of the CFC as the value for naming strategy. This CFC must implement cfide.orm.INamingStrategy interface.
Again, we have hibernate to thank for this but I really love how ColdFusion has implemented this for us, great job guys!

#1 by Justin Scott on 8/7/10 - 9:19 PM
#2 by Dan Vega on 8/8/10 - 11:28 AM
#3 by James Brown on 8/9/10 - 5:11 AM