[Looking for Charlie's main web site?]

IBATIS as a possible new approach to object-relational mapping for CFML?

I'd like to put out for consideration by the CFML community a possible new approach for object-relational mapping (ORM), using an existing Apache project called IBATIS as a model. I'm wondering if someone may want to consider implementing a CFML version of it for a new ORM approach in CFML.

IBATIS, at http://ibatis.apache.org/ is an alternative ORM approach based on a concept of SQL Maps, which in essence are simply SQL statements stored in XML files with a well-defined API for mapping and manipulating those in your app. The approach does not generate SQL for you, but rather is intended to serve as a means to segregate to XML files--and manage via an API--the SQL that may already exist substantially for existing apps or for new apps that may simply require some hand-coding of SQL. (The last sentence added after some comments suggest that this point made later in the post was missed.)

The benefit is that since CFML folks are already knee deep in SQL, it brings a measure of architecture without completely detaching them from the SQL they know and love (or at least tolerate).

If that sounds counter to other ORM approaches, which often generate the SQL automatically and/or intentionally hide it from you, that's because it is quite different. I'll grant that there are many who would benefit from having an architecture remove SQL from their control. It's just that this seems an alternative worth considering.

I certainly don't mean to knock at all the other CFML-based ORM implementations that exist already (such as Arf, ObjectBreeze, Transfer, and Reactor). Each approach has its place and pros/cons. As the other CFML-based ORM frameworks tend to be based on existing approaches from other platforms, I'm merely pointing out this alternative as a possibly useful model.

I'm also not offering here my own new CFML-based implementation based on IBATIS. But note that there are currently implementations for Java and .NET at the Apache site, so it shouldn't be tough for someone to leverage the Java implementation in CFML.

It strikes me that the IBATIS approach may be closer to the way fuseboxers and others segregate their queries into their own CFML file. Perhaps this approach of storing them in an XML file instead and using an API to access the results would offer a better though still somewhat familiar approach to abstracting queries.

I was sharing the idea with Sean Corfield at CFUnited last night, and he was intrigued. After I sat in on his excellent presentation on objects and persistence, we discussed it again and he had started looking into it overnight. Perhaps it could make it into FB 6? :-)

I'm hoping someone may want to take the ball and run with it. If you're intrigued, considering discussing it with Sean or take it on yourself, or just continue the conversation. Hope it proves helpful.

You know Charlie, this looks kind of interesting. Even if it isn't something I'd really use, I think I may try to write it. I think it could be interesting.
# Posted By Raymond Camden | 7/1/06 3:16 PM
Great, Ray. Thanks for considering it. (Like you need another project, though!)
# Posted By Charlie Arehart | 7/1/06 3:43 PM
I should also mention that I was introduced to IBATIS myself from a very old friend, Charles Carroll, a frequent contributor to the .NET community. He's written of it at:


He's an ardent supporter of ORM frameworks. :-) I just noticed he also asserts that IBATIS has been used at Myspace, though I have to admit I never heard of among the devlopers I worked with there while I was at New Atlanta. He speaks of it at http://weblogs.asp.n... Lots of interesting comments clarifying the misconception being spread among .NET fans that it was "all asp.net" that makes Myspace run so well. It's still substantially CFML, running on BD.
# Posted By Charlie Arehart | 7/1/06 3:55 PM
Hey Charlie,

I happen to work with someone who's both an IBATIS contributor and ColdFusion developer - I'm going to point him towards this post next week when we next speak.

# Posted By Joe Rinehart | 7/1/06 11:08 PM
Ha, I think I pointed Sean at iBatis quite awhile ago, but he must not have really taken a look until now. :)

I've worked a bit with iBatis over the last few months and have been working on implementing it to talk with ColdFsion (I context switch between ColdFusion, Java, and occasionally Python). There are some pretty big hurdles to overcome with iBatis for the "typical" CF Developer. For one thing, as far as I can tell you would still have to write, compile, and deploy Java as the iBatis ORM Framework returns maps or lists of Java objects (which you create on your own) for the result set of queries.

One good thing is that you can pass off database connections to iBatis ORM directly, so you could still use the ColdFusion native datasources and db connections (but, in an unsupported way)...

It also uses a newer version of Log4J than ColdFusion (as does pretty much every Java product) so the two conflict with each other.. granted you can write a class loader to get around that, but writing class loaders sucks. I really get upset when trying to integrate Java foo into CF because of all of the old libraries it uses, the biggest offender being Log4J.

And lastly, when testing any java code inside of CF you have to restart your app server... ColdFusion is a bit of a gorilla and it can get old waiting for server restarts to try out code changes...

You would almost be better off writing a port of iBatis which supported the iBatis XML syntax, IMHO, just like the iBatis.net stuff.
# Posted By Brandon Harper | 7/2/06 3:39 PM
Brandon, I had assumed a port is what Charlie had meant. :) That was the route I was going to take.
# Posted By Raymond Camden | 7/2/06 4:00 PM
Hi Charlie ,<br><br>

You have thrown a very good idea.<br><br>

For the last 6 months I have tried to integrate the most famous Java ORM framework (
<a target="_blank" href="http://www.hibernate...">Hibernate</a>,
<a target="_blank" href="http://ibatis.apache...">IBATIS</a>,
<a target="_blank" href="http://db.apache.org...">TORQUE<a/>) <br>with Coldfusion but many problems remain. <br> <br>

- Those frameworks work with <a target="_blank" href="http://en.wikipedia....">POJO</a> : <br><br>

You have to create, compile, package and deploy your Java objects.<br>
For many coldfusion developers it could be a new and not very interesting thing to do.<br>
( deploy, restart the Coldfusion service ......)<br><br>

<i> You could easily do it with CFC :</i> <br>

I'm sorry to say that but using CFC as a POJO it's just a mistake. <br>

* Instantiate CFC is creating many Java objects just for getting and setting values. (too heavy ....) .
   It's perfect for a persistent service but not for a simple 'Bean'. <br> <br>

- Heavy use of the DAO pattern : <br><br>

If you want to integrate those frameworks you have to use DAOs, JDBC Drivers and manage your own transaction.
But suddenly your data access layer is not any more coded with Coldfusion CFC but with real
Java object. <br><br>

<i>Then the real question is what the use of CFQUERY and CFTRANSACTION ?</i> <br> <br>

+ <b>What could be done ?</b><br>

If you want to integrate those frameworks the only thing you have to do is
to rethink your application layers, your data access layer.<br>
Your business layer and display could be done with Coldfusion and you data access in java.<br>
You could then test your data access out of your Coldfusion Application server ( Eclipse Ide or IDEA or NETBEAN)
and integrate this layer afterward into your Coldfusion project or Java project.<br>
You will have acces then to all the Java world of ORM, JUnit testing, JDBC ....<br>

+ <b>What not to do ? </b><br>

TO PORT ?????????!!!!!!!!!!!!!!!!<br>

Please do not spend time to port.<br>

For the <a target="_blank" href="http://msdn.microsof...">.NET platform</a>, is normal to port
but for the <a target="_blank" heref="http://www.adobe.com...">Coldfusion Application server</a><br>
based on <a target="_blank" href="http://java.sun.com/...">Java</a>, it's just an error to port.

In fact we should be using those libraries.<br>
What's the point of being on top of a Java Runtime and porting tools ?<br>

If you want to do so , please go back to Coldfusion 5 or previous.....<br>

With CFEclipse the coldfusion community has gone into a good trend, that's give us a
whole new world we shouldn't miss.
We might have to change our view on Java and Coldfusion integration.

Serge Tan Panza
# Posted By Serge Tan Panza | 7/3/06 5:40 AM
Charlie, after you post I went examining iBATIS and am a little confused as to the full value of the project as it relates to CF. In reviewing the tutorials for both the SQL Map and DAO portions, it seems as though both projects work independently of one another (thought they can work together). The DAO project did not generate any SQL code, but could use SQL Map for persistance. However, the SQL Map examples had you writing out CRUD sql but instead of a CFC it was into an XML file. It would abstract exactly which dbms it seems, but did not handle the SQL coding for you (unless you used the XML syntax which they didn't cover much but seemed much too explicit to save you any time). Am I understanding the project correctly? If so, I am not completely clear on the value this has, since you are forced to write the CRUD out anyway but in their XML document instead of in straight CFML.
# Posted By Brian Rinaldi | 7/3/06 3:30 PM
Brian, I'm sensing that perhaps in your enthusiasm to jump over to the site, you missed reading all my comments. :-)

In the paragraph after the one offering link to the Ibatis site, I said, "If that sounds counter to other ORM approaches, which often generate the SQL automatically and/or intentionally hide it from you, that's because it is quite different. I'll grant that there are many who would benefit from having an architecture remove SQL from their control."

So, yes, you are (now) understanding it correctly. It DOES NOT generate the SQL for you. For those who for so long in our community have done that themselves, it opens a door of different possibility. The rest of my post offered more on that assertion. Hope that helps.
# Posted By Charlie Arehart | 7/3/06 4:30 PM
I've added some commentary to the end of the 2nd paragraph above to clarify the point Brian raised. Thanks. I have to realize that some may not read the whole post before heading off to read about it, so I've made it bold also.

If that's not what the problem was, Brian, no offense. If it was otherwise still unclear, I hope the new sentence will help readers.
# Posted By Charlie Arehart | 7/3/06 4:41 PM
Charlie, it's worse...I read it but only heard what I wanted to hear I suppose. However, I still am not sure of the value of this. It seems that you have gone from writing your SQL in straight CFML to writing it in some proprietary XML format. It strikes me that this would be both harder to build and harder to move should you ever choose to drop iBATIS.
# Posted By Brian Rinaldi | 7/3/06 5:23 PM
Well, it's not about writing SQL "in some proprietary XML format" so much as storing it there. You still write it as you normally would. The point is simply that it's no longer buried in CFML but rather in a reusable store with a well-defined API.

I'll grant that for some it may seem hardly worth the bother, but then that's the case with many frameworks. They always seem to be extra work, but the goal is to bring order and consistency to the development process.

It simply struck me that this may make more sense than merely segregating them in CFCs and qry files. But that's why I threw it out there for others to give further consideration. If this clarification about it still leaves you cold, then that's one vote "nea".

But let's do keep in mind that if your preference is more because you prefer the SQL being generated, rather than ever being built by hand, then that's a separate approach to the problem of managing SQL in our apps. I'm merely proposing that each may have its place, and this one may be better suited to CFML folks either used to, preferring to, or needing to build SQL manually.
# Posted By Charlie Arehart | 7/3/06 5:33 PM

How exactly did you get CF to play nicely with iBatis? I am receiving exceptions with logging. I am assuming that this is due to the Log4J conflict that you referred to.

# Posted By David Ringley | 7/11/06 3:29 PM
I'm very interested in using iBatis in Coldfusion. We've got a couple of high-level Java/CF developers who would write the object model and the DAOs, essentially returning the results to any business CFC in CF.

What's the classloader Log4J workaround? Can you point me to any literature.

As for rewriting it, I agree with the above poster that that's a mistake - one of the benefits of having CF sit on top of Java is so we can leverage all these nice tools.

We've used POJOs (and Collections of POJOs) in CF (using DAOs written in Java) and other than losing the nice <cfoutput query=""> syntax, there aren't really any downsides.

Having a consistent POJO that is used everywhere by all the CF developers, whether they're displaying/editing a single record or a list of results, the benefits far outweigh any difficultly setting it up in the first place, IMO.

Anyway, if anyone gets the Apache iBatis (the Java one!) working with CF, I'd be most interested.


# Posted By Tony Blake | 7/13/06 5:43 AM
Any updated on the iBATIS front? Anyone still looking to port it? How is it going working with the Java one? Anything new to report anyone?!
# Posted By Peter Bell | 11/1/06 12:49 PM
Hi, Peter, nothing from me. (You may know that, from our discussions on your blog, at http://www.pbell.com..., but I want readers here to understand.)

Anyone else? :-)
# Posted By Charlie Arehart | 11/1/06 1:07 PM
Hi Charlie,

I know this is an old post, but I am pleased to report that I just got CF and iBatis talking to each other tonight.

My sample is still pretty rough around the edges but I'll package it up in the next day or to and share what I've done.

# Posted By Andrew Myers | 12/12/09 7:28 AM
Here's a link to where I blogged about doing this:

# Posted By Andrew Myers | 12/13/09 10:07 PM
Great to see, Andrew, and thanks for both following up on it and especially for mentioning it here, should others care to look further info it. I will admit I never got beyond the blog post, since there was so little interest. Glad it may prove fruitful (the CF/Ibatis integration possibility) in the end. Cheers.
# Posted By Charlie Arehart | 12/13/09 10:18 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.005. (Want to validate the html in this page?)

Managed Hosting Services provided by
Managed Dedicated Hosting