Sam Farmer head shot

Sam Farmer

Growing up I never imagined I would play bass guitar for the Dave Matthews Band. And indeed it never happened.

But I have become a passionate and pretty good web developer.


Example of multiple datasources for ORM in 9.0.1

ColdFusion 9.0.1 brings multiple datasources support for ORM. Here is how to set it up.

In this example, we are going to use both the cfartgallery and cfbookclub datasources.  In the Application.cfc we will make the cfartgallery the default datasource.  Optionally we are going to set the dbcreate rules differently for the two datasources.  (We could also do this for the schema, catalog, dialect and sqlscript settings.)

 

component
{
this.name="multi";
this.ormEnabled=true;
this.datasource="cfartgallery";
this.ormsettings = { dbcreate={ cfartgallery="update",
cfbookclub="none"} };
}

 

From cfartgallery we will use the Art table as an object.  As cfartgallery is the default datasource, this is set up as usual:

 

component persistent="true"
{
property name="artID" fieldtype="id" ;
property name="artistID";
property name="artname";
property name="description";
property name="prize";
property name="largeimage";
property name="mediaID";
property name="issold";
property name="samColumn";
}

 

For any tables from the cfbookclub datasource there is an additional attribute "datasource" for the component:

 

component persistent="true" datasource="cfbookclub"
{
property name="bookID" fieldtype="id";
property name="authorID";
property name="title";
property name="bookdescription";
property name="isspotlight";
}

 

We can then get the data and dump it like so:

 

books = entityLoad("BOOKS", {}, {maxResults=2});
writeDump(books);
art = entityLoad("ART", {}, {maxResults=2});
writeDump(art);

 

 Pretty straighforward and pretty cool stuff.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Great post! This is exactly what I needed. I am having one related problem. Datasource A is MS SQL Server and datasource B is Sybase SQLAnywhere. I'm getting the error from dsn B...

Unable to determine Dialect to use [name=SQL Anywhere, majorVersion=11]; user must register resolver or explicitly set 'hibernate.dialect'

It sounds easy, just define the dialect... But where? And why would I need to when Sybase SQLAnywhere should auto detect.
# Posted By Jamie | 11/15/11 12:32 PM
Ah! Nevermind, I got it, have to set it at the application level in ormsettings, exactly as you post states. Thanks again!
# Posted By Jamie | 11/15/11 12:36 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.7. Contact Blog Owner