Configure ORM

The configuration for ORM is done in Application.cfc which makes this configuration application specific. For a ColdFusion application to use ORM, the following are the mandatory settings that need to be configured:

  1. Enable ORM for the application. To do this, set the ormenabled property to true in the THIS scope of application.cfc

  2. Provide the data source name by either setting data source property to true in the THIS scope of application or by defining it in ORM configuration for the application.

    Note that the data source should be configured on the server.

The ORM configuration is specified using a struct called ormsettings, which is defined in the THIS scope of Application.cfc. The following table describes the settings for ORM that can be defined in Application.cfc.

Property Name



Specifies whether ORM should be used for the ColdFusion application.Set the value to true to use ORM. The default is false.


Defines the data source that should be used by ORM.


The struct that defines all the ORM settings. For details, see ORM settings

ORM settings

The following settings can be set in the ormsettings struct that ColdFusion uses to configure ORM. All these settings are optional. If you specify the value of any ORM setting to true or yes, then the setting is enabled, otherwise it is disabled.

Property Name





Specifies whether ColdFusion should automatically generate mapping for the persistent CFCs. If autogenmap=false, mapping should be provided in the form of .HBMXML files.


Added in ColdFusion 9.0.1


Lets you specify if ColdFusion must manage Hibernate session automatically.

  • If enabled: ColdFusion manages the session completely. That is, it decides when to flush the session, when to clear the session, and when to close the session.

  • If disabled: The application is responsible for managing flushing, clearing, or closing of the session. The only exception is (in the case of transaction), when the transaction commits, the application flushes the session.

ColdFusion closes the ORM session at the end of request irrespective of this flag being enabled or disabled.



Specifies the location of the configuration file that should be used by the secondary cache provider.This setting is used only when secondarycacheenabled=true.

See Secondary level cache for details.



Specifies the cache provider that should be used by ORM as secondary cache. The values can be:

  • Ehcache

  • JBossCache

  • Hashtable

  • SwarmCache

  • OSCache

Fully qualified name of the class for any other cache provider.

This setting is used only when secondarycacheenabled=true.

See Secondary level cache for details.



Specifies the default Catalog that should be used by ORM.



Specifies the directory (or array of directories) that should be used by ColdFusion to search for persistent CFCs to generate the mapping. If cfclocation is set, ColdFusion looks at only the paths specified in it. If it is not set, ColdFusion looks at the application directory, its sub-directories, and its mapped directories to search for persistent CFCs.



Specifies the data source that should be used by ORM. If it is not specified here, then the data source specified for the application is picked up. Use the following convention to specify a datasource name: this.datasource="<datasource_name>";



ColdFusion ORM can automatically create the tables for your application in the database when ORM is initialized for the application. This can be enabled by using dbcreate in ormsettings. dbCreate takes the following values:
  • update: Setting this value creates the table if it does not exist or update the table if it exists.

  • dropcreate: Setting this value drops the table if it exists and then creates it.

  • none (default): Setting this value does not change anything in the database schema.



Specifies the dialect.

ColdFusion supports the following dialects:
  • DB2

  • DB2AS400

  • DB2OS390

  • Derby

  • PostgreSQL

  • MySQL

  • MySQLwithInnoDB

  • MySQLwithMyISAM

  • Oracle8i

  • Oracle9i

  • Oracle10g

  • Sybase

  • SybaseAnywhere

  • MicrosoftSQLServer

  • Informix

Apart from these dialects, you can specify custom dialects by using the fully qualified class name.

Note: For Microsoft Access, dialect cannot be detected automatically. Use Microsoft SQL Server as the dialect for it.



Specifies whether ORM Event callbacks should be given. See Event Handling in CFC for details.



Specifies whether ormflush should be called automatically at request end. If flushatrequestend is false, ormflush is not called automatically at request end.

See ORM session management.



Specifies whether the SQL queries that are executed by ORM will be logged. If LogSQL=true, the SQL queries are logged to the console.



Defines database standard and naming convention. See Naming strategy.



The Hibernate configuration file.

This file contains various configuration parameters like, dialect, cache settings, and mapping files that are required for the application. For more details, see

The settings defined in the ormsettings override the settings defined in the Hibernate Configuration XML file.The connection information in the Hibernate Configuration XML file is however ignored because ColdFusion uses its own connection pool.

You will need to use this only when you need to use a hibernate setting that is not available using ormsetting.



Specifies whether the generated Hibernate mapping file has to be saved to disc. If you set the value to true, the Hibernate mapping XML file is saved with the filename "CFC name".hbmxml in the same directory as the CFC.

If any value of savemapping is specified in CFC, it will override the value specified in the ormsetting.



Specifies the default Schema that should be used by ORM.



Specifies whether secondary caching should be enabled. See Use secondary cache for details.


Added in ColdFusion 9.0.1


Lets you specify if ColdFusion must skip the CFCs that have errors. If set to true, ColdFusion ignores the CFCs that have errors.



Path to the SQL script file that gets executed after ORM is initialized. This applies if dbcreate is set to dropcreate. This must be the absolute file path or the path relative to the application.The SQL script file lets you populate the tables before the application is accessed.



Specifies whether the database has to be inspected to identify the missing information required to generate the Hibernate mapping. The database is inspected to get the column data type, primary key and foreign key information.

Sample Application.cfc

<cfset = "ArtGallery"> 
    <cfset this.ormenabled = "true"> 
    <cfset this.ormsettings={datasource="cfartgallery", logsql="true"}>


Monitoring SQL queries that get generated and executed by ORM is critical for troubleshooting and performance optimization.

You can monitor and log the queries by:

  • Defining logsql in ormsettings: This is a simple way to quickly enable SQL logging. The flag should be enabled in application.cfc:

    <cfset this.ormsettings.logsql = "true">

    This logs all the SQL queries that are generated by Hibernate to the console and server’s output log file.

  • Using Hibernate uses log4j for its logging and you can completely control its logging including SQL by modifying the, which is present under <CF_HOME>/lib directory.

    Following is a sample snippet from the file:

    ###--------------- Hibernate Log Settings ------ 
    ### Set Hibernate log, HIBERNATECONSOLE 
    ### log just the SQL, HIBERNATECONSOLE 
    ### Also log the parameter binding to the prepared statements. 
    ### log schema export/update ###, HIBERNATECONSOLE 
    ### log cache activity ###, HIBERNATECONSOLE 
    # HibernateConsole is set to be a ColsoleAppender for Hibernate message  using a PatternLayout. 
    log4j.appender.HIBERNATECONSOLE.layout.ConversionPattern=%d{MM/dd HH:mm:ss} [%t] HIBERNATE %-5p - %m%n%n 

    These settings control the SQLs that are generated for entity operations, how the data is bound to the statement while executing, what SQLs are generated for DDL, and what operations are performed on the secondary cache. All the logs get logged to console using HIBERNATECONSOLE which is actually a console appender. It can easily be changed to a FileAppender, which will then be logged to a log file. The configuration controls the logging for the following:

    • SQL generated for entity operations

    • Parameter binding for the prepared statements

    • SQL generated for DDL

    • Secondary cache operations

    With the default settings, all the logs get logged to console. You can also direct the logging to a log file using the FileAppender provided by log4j.

    See log4j for more details on Appenders.

    Log4j Properties


    This controls when and how the SQL will be logged. DEBUG says all the SQL will be logged

    This logs the parameter binding to the prepared statement.

    Logs SQL for DDL i.e schema export.

    Logs secondary cache information.