Using FusionReactor's JDBC Driver Wrapper With ColdFusion 9 ORM
FusionReactor's JDBC Driver Wrapper is a great addition to ColdFusion 9's Object-Relational Modelingcapabilities. You can use it to spy on what Hibernate (ColdFusion's ORM provider) is really doing to your database.
This article doesn't go into detail about what ORM is, or how it works – there are many posts and articles on the web which cover this in detail:
Adobe's integration of the third-party Hibernate framework brings ORM functionality to your CFC-based applications. This brings with it some new, important concerns for ColdFusion developers:
- How is Hibernate converting my entity operations to SQL?
- Why are they running so slowly?
- How is Hibernate locking the DB?
You can use the setting Application.cfc setting this.ormsettings.logSQL to have Hibernate dump its SQL to the log as it's created, but you'll soon find the log is overflowing with data.
- FusionReactor's JDBC Driver Wrapper associates your queries with the precise request - and ultimately CFC/CFM line of code - in which they run.
- You can use the JDBC tab in FusionReactor's Request View to see what ran, how long it took, and how many rows came back - great for tuning and catching runaway queries.
Getting this working is simple, just follow the steps below.
- Download and install FusionReactor - you'll need version 3.5.0 or better. You can get a 10-day free trialhere.
- You'll need to create a wrapped datasource. This won't replace your original datasource, but it will allow our lightweight wrapper to spy on he interaction between ColdFusion, Hibernate and the database.
- You can use the instructions in the FusionReactor JDBC Driver Wrapper User Guide, or download and use our free tool (just run the tool and have it wrap your datasource automatically).
- Once you've got a wrapped datasource, change your ORM datasource in Application.cfc to point to the new datasource.
this.datasource = "orm_WRAPPED";
.. for example.
Once you've installed the FusionReactor JDBC Driver Wrapper, and adjusted your Application.cfc to point to the wrapped datasource, you can have a look at the collected data. We ran the01_createmusician.cfm script from Mark Mandel's introductory app (from Introducing ORM in Adobe ColdFusion 9), with this.ormsettings.logSQL = true turned on in our Application.cfc.
What came out in the log was:
Hibernate: insert into Musician (name, age) values (?, ?) Hibernate: select currval('Musician_musicianID_seq')
But that's not only what ran - the log isn't showing you everything. Inspecting the JDBC tab of the request in FusionReactor actually shows us exactly what's going on:
There's actually a whole bunch of overhead. We turned on "Record In Order" in FusionReactor's JDBC Settings, so this list is in time order – including a whole set of alters, drops, creates (JDBC transaction 1), then the load of sample data (transactions 2 and 3), the actual insert from the CFM page itself (transactions 4 and 5), and the select from the page for the dump (transaction 6).
We think FusionReactor's JDBC Driver Wrapper is an awesome tool to spy on exactly how Hibernate and ColdFusion 9 is interacting with your database. Object-Relational Modeling is going to revolutionize how you deal with your databases, and FusionReactor is going to make your life easier in analyzing and solving problems.