Whatever message this page gives is out now! Go check it out!

Configuring the application to use multiple data sources

Last update:
Jun 9, 2026
Application Platforms
Ask AI
Search
Web Application Platforms
Whatever message this page gives is out now! Go check it out!
ColdFusion
  1. Home
  2. Adobe ColdFusion User Guides
  3. Configuring the application to use multiple data sources
Copy page
Last update:
May 18, 2026
Configure Persistent CFCs with the attribute datasource pointing to the appropriate data source. You can specify the attribute data source on the CFC using the tag cfcomponent or by specifying the annotation on Component in the CFC definition. If you do not specify a data source, the default data source is used for that CFC. Since a Hibernate configuration uses a single data source, all related CFCs (using ORM relationships) must have the same data source.

Example

Art.cfc
<cfcomponent persistent="true" datasource="artgallery" table="Art"> 

... 

</cfcomponent>
Author.cfc
<cfcomponent persistent="true" datasource="bookclub" table="author"> 



</cfcomponent>

ORM settings

The following are the data source-specific ORM settings for which you can specify  string  or struct values in the Application.cfc:
  • schema
  • catalog
  • dialect
  • dbcreate
  • sqlscript For multiple data sources, a struct can be specified with data source name as the key and the appropriate setting as the value. If a string value is specified, it applies to the default data source of ORM.

Example 1

<cfset this.ormsettings.dbcreate={artgallery="dropcreate", bookclub="none"}>

Example 2

<cfset this.ormsettings.dbcreate="dropcreate"> If multiple data sources are used for ORM, these settings apply to the default ORM data source.

Mapping using Hibernate mapping files

In multiple data source scenarios, the data source information must be provided in the CFC (and not in .hbmxml file).  Also, all CFCs used in one .hbmxml file must have the same data source.

Example

The following example illustrates two different entities using two different data sources. In this example, art.cfc and artist.cfc are related and therefore use the same data source.art.cfc
<cfcomponent persistent="true" table="art" datasource="cfartgallery"> 

<cfproperty name="ArtID" fieldtype="id" generator="native"> 

<cfproperty name="ArtName"> 

<cfproperty name="IsSold"> 

</cfcomponent>
artists.cfc
<cfcomponent persistent="true" table="artists" datasource="cfartgallery"> 

<cfproperty name="ArtistID" fieldtype="id"> 

<cfproperty name="FirstName"> 

<cfproperty name="LastName"> 

<cfproperty name="art" fieldtype="one-to-many" cfc="art" fkcolumn="ArtistID"> 

</cfcomponent>
authors.cfc
<cfcomponent persistent="true" table=authors datasource="cfbookclub"> 

<cfproperty name="AuthorID" fieldtype="id"> 

<cfproperty name="LastName"> 

<cfproperty name="FirstName"> 

</cfcomponent>
index.cfm
<cfoutput>Original Data<br></cfoutput> 

<cfset artistObj = EntityLoad("artists", 1, true)> 

<cfoutput>#artistObj.getArtistID()# | #artistObj.getFirstName()# | 

#artistObj.getLastName()#<br></cfoutput> 

<cfset artObj = artistObj.getart()> 

<cfoutput>#artObj[1].getartname()# <br></cfoutput> 

<cfset authorObj = EntityLoad("authors", 1, true)> 

<cfoutput>#authorObj.getFirstName()#</cfoutput> 

<cfoutput>#authorObj.getLastName()#</cfoutput>
Share this page
Was this page helpful?
Yes, thanks
Not really
We're glad. Tell us how this page helped.
Found the answer to my problem
Understood the instructions
Liked the feature
Other suggestions
Skip
Submit
We're sorry. Can you tell us what didn't work for you?
Didn't find the answer to my problem
Couldn't understand the instructions
Didn't like the feature
Other suggestions
Skip
Submit
Thank you for your feedback. Your response will help improve this page.
Was this helpful?YesNo We are sorry the content didn't meet your needs.Share additional feedback to help us improve.0/255|Character limit exceeded.SubmitSkipThank you so much for sharing your feedback!

On this page

Register for Adobe ColdFusion Summit 2026
AI TRAINING
Build ColdFusion AI workflows
ColdFusion
Support
Resources
Adobe Account
Adobe
Featured products
Copyright © 2026 Adobe. All rights reserved.

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page