Photo from Chile

Managing Bi-directional Relationships in ColdFusion ORM - Array-based Collections Follow-up

Barney Boisvert made a comment on my last post on this topic, suggesting that a nice way to reduce the amount of code one has to write, and to boost performance, would be to have one side in a bi-directional relationship simply delegate to the other side. This way you are only writing the code to do the work in one object, and it also reduces the number of hasX() calls.

I changed my code to try this technique out, and I quite like it. Because the code is slightly different I figured I might as well write about it here, to keep my posts on this topic up to date.


Managing Bi-directional Relationships in ColdFusion ORM - Array-based Collections

It's important to know that when you have a bi-directional relationship you should set the relationship on both sides when setting one side. There have been a number of discussions about this on the cf-orm-dev google group, including this one in which Barney Boisvert provides a very good explanation of why this is important. Brian Kotek has also written two articles on the subject in the past. If you're not already familiar with this topic I suggest you check out those links.

The general recommendation for addressing this requirement is to override the methods in your objects that set one side of the relationship (e.g., setX(), addX() and removeX()) so that they'll set both sides, rather than just the side of the object that was invoked. While doing some testing of the new CF9 ORM adapter for Model-Glue along with the new scaffolding mechanism that we're developing I needed to address this issue for a many-to-many bi-directional relationship. I found that there were a few wrinkles that made the task not quite as straightforward as I has originally imagined, so I figured I should share what I came up with.


The This Week in ColdFusion Podcast is Back!

That's right, the mighty fine folks who bring you the This Week in ColdFusion podcast have released a new episode. After what seems like an interminable hiatus, the boys are back and guess what? I'm on it too! I was interviewed about the upcoming cf.Objective() conference and the incredible pre-conference training that will be available. I also discussed the Pecha Kucha BOF that I am organizing.

After my cameo Brian and Mike had a lively and informative chat about design patterns, which I stuck my nose into from time to time. It was great fun and I encourage you to give it a listen. It's available via iTunes, and can also be listened to or downloaded directly from the show page.

Connecting to Derby Databases on OS X using SQuirreLSQL

Today I had a need to connect to and mess around with one of the Derby databases that ships with ColdFusion. I don't have RDS set up, plus I'm fairly certain that RDS does not allow you to modify data in tables, so I needed a solution. I had no idea where to start, so of course I simply Googled "derby database client tools" and one of the first links I saw was an article entitled Using SQuirreL SQL Client with Derby, by Susan Cline. I recalled that SQuirreLSQL is a client that runs on OS X, so I clicked.

Boy was I glad that I did. The article covers just about everything you need to know to get up and running with Derby on OS X, and a whole lot more, and I highly recommend reading it. If you don't feel like seeing the details, I've included a simple step-by-step guide below:

  1. Install SQuirreLSQL
    1. Download SQuirreLSQL from the downloads page. I clicked the link labelled Install jars (and source) of SQuirreL 3.1 for MacOS X.
    2. Open up a terminal window and change to the folder where the downloaded jar file is located.
    3. Run the install package by typing the following command:
      java -jar squirrel-sql-3.1-MacOSX-install.jar
      where squirrel-sql-3.1-MacOSX-install.jar is the name of the file you downloaded.
    4. Tell the installer where to put the app file (I chose /Applications/, and choose the plugins to install. I chose a whole bunch of plugins as I wanted to see what they do, but make sure you choose the Derby plugin.
  2. Configure SQuirreLSQL to Use Derby
    1. Start SQuirreLSQL by running the app file that you just installed.
    2. Click the Drivers tab.
    3. You should see Apache Derby Embedded as one of the drivers listed. If it has a blue check mark beside it then SQuirreLSQL is ready to access Derby databases, and you can continue with Configuring SQuirreLSQL to Use Your Database, below. On the other hand, if, like me, you see a red x beside it, then you need to continue with the following steps.
    4. Select Apache Derby Embedded in the list and click the pencil icon, which allows you to edit the driver.
    5. Click the Extra Class Path tab and then click the Add button.
    6. Browse to a folder that contains the derby.jar file. It should be located in the /lib folder of your ColdFusion server. For example, on my machine it's in /Developer/CF9/servers/cfusion/cfusion-ear/cfusion-war/WEB-INF/cfusion/lib. Select the derby.jar file and click the Choose button.
    7. Now click the List Drivers button which should populate the Class Name select box.
    8. Select org.apache.derby.jdbc.EmbeddedDriver from the Class Name select box, and click the OK button.
    9. You should be returned to the main SQuirreLSQL window and see the message
      Driver class org.apache.derby.jdbc.EmbeddedDriver successfully registered for driver definition: Apache Derby Embedded
      at the bottom of the screen. The Apache Derby Embedded driver should now have a blue check mark beside it.
  3. Configuring SQuirreLSQL to Use Your Database
    1. Click on the Aliases tab.
    2. Click the blue + symbol to add an alias.
    3. Give your alias a name. I chose the name of the database, so I put cfartgallery into the Name text box.
    4. Choose Apache Derby Embedded from the Driver select box.
    5. In the URL text box, replace the text <database> with the location of your database. I went to the datasource information in the ColdFusion Administrator and copied the contents of the Database Folder text box from there. The value I used was
    6. Check the Auto logon check box.
    7. Click the Test button. You should see a dialog pop up saying "Connection successful".
    8. Click the OK button. You should now be able to connect to the cfartgallery database!

Once again I just want to point out that all of this is covered by Susan Cline in her excellent guide. If by any chance she ever reads this, I'd like to thank her for this wonderful and well written resource.

Coming to cf.Objective()? What Interests You?

The folks organizing cf.Objective() are in the process of finalizing the BOF sessions and are looking for feedback from you!

In case you're unfamiliar with the term, BOF stands for Birds of a Feather and it's an informal session in which the attendees get a chance to chat about a topic with other developers who have similar interests. It's a great chance to get a bit more interactive - you get to participate rather than just sit and watch.

I suggested that during one of the BOF sessions we do a series of Pecha Kucha presentations, which are similar to Ignite presentations, and my suggestion was graciously accepted by the committee. I blogged about this session previously and am still looking for volunteers to present, so if you're interested in that please mosey on over to that blog post and comment.

There are seven remaining BOF slots, and Sean Corfield has blogged about the other topics that have been suggested thus far. Here's a summary:

  • Open BlueDragon
  • Security
  • Extending Mura
  • Home Brewed ColdFusion Monitoring
  • Being Agile
  • Guitar Hero
  • ColdFusion 10
  • Mobile Development
  • SciFi
  • Photography
  • Poetry Slam
  • Open Source Project Discussion
  • Test-Driven Development (TDD)

Decisions will be made in the not-too-distant future, and to help you vote on topics and make new suggestions a survey has been created. It's a one-question survey that should take no more than about 30 seconds to complete, so if you'll be attending cf.Objective() please take the time to add your opinion.

I hope to see many of you at cf.Objective() in April!

CFinNC is Dead. Long Live NCDevCon!

In October of last year I had the honour of speaking at CFinNC, a ColdFusion / Flex / AIR conference organized by the Triangle Area ColdFusion User's Group. It was an outstanding conference; well run, with informative sessions on timely topics, which is pretty amazing considering that it was absolutely free.

The mad geniuses behind CFinNC are throwing another conference this year, and this time it's called NCDevCon. It will be held May 22-23, 2010 on the Centennial Campus of NC State University in Raleigh, North Carolina. This year's conference is planning on covering a wide variety of web development and design topics including ColdFusion, Flex and AIR, Javascript and CSS, and, just like last year, it's free as in beer.

Registration is already open, as is a Call For Presentations. I'm hoping to get a chance to speak again this year, but even if I don't I'll be there to partake in the learning and festivities. If it turns out to be anywhere near as good as CFinNC (and I'm sure it will), it will be a conference that you won't want to miss.

Become a ColdFusion ORM Ninja in Just Two Days!

I've mentioned previously that Mark Mandel, the mastermind behind Transfer ORM, JavaLoader, ColdDoc, and now the lead developer of Coldspring, and I have developed an intensive, two-day, hands-on workshop on ColdFusion's new ORM features. We will be delivering that workshop, Developing Applications with ColdFusion 9 Object Relational Mapping, in Minneapolis, MN on April 20-21, 2010 which are the two days immediately preceding the cf.Objective() conference.

Really? I Can Master ColdFusion ORM in Two Days?

You bet you can! This is an extreme hands-on workshop. We won't be lecturing at you, we'll be working with you. For each concept that we cover we'll be writing code together, both the instructor and the students, working towards building a single, working application. Then, once we've done that together, you'll be let loose on your own to practice the concepts again on your very own project, which is yet another application which will be built incrementally using the concepts that you just learned. This means you'll have lots of chances to practice your newfound skills, and, more importantly, to make your own mistakes. You'll either figure out how to fix your mistakes yourself, with the help of one of your fellow students, or with the help one of the two instructors. You'll learn by doing, and what's more, you'll leave the class with lots of examples of working code that you wrote yourself.

This is why we say that we can help you master ColdFusion ORM in just two days. Not only will you be ready to start using it in your next project, but you'll also be in an ideal position to teach it to your fellow developers.

About the Instructors

I've been working with Transfer ORM for a few years, and have been working with ColdFusion's ORM integration since early in the product beta. I've blogged about it extensively, delivered a number of one-hour presentations on the subject and have created and regularly contribute to a Google group (cf-orm-dev) dedicated to discussing some of the more advanced and esoteric topics around ColdFusion's ORM integration.

As for Mark, in addition to creating his own ColdFusion-based ORM (Transfer), he's also worked extensively with Hibernate (the ORM that is integrated into ColdFusion 9) and is considered by many to be the foremost expert in all things ORM in the ColdFusion community. This therefore represents a unique opportunity to learn about this new, exciting and productivity enhancing technology from two people who know it very well, and have real-world experience developing with it.

Do I Have to Be an OO Guru to Attend?

Definitely not! We assume no prior knowledge of ORMs or Object Oriented programming, and the techniques that we teach can be used, if you wish, in a totally procedural application. So you neither need to know OO to join in, nor do you need to learn OO in order to use what you learn in your own work (although we would encourage you to do so). Some experience working with CFCs would be helpful, but we can get you up to speed pretty quickly even if you lack that.

Where is the Workshop Being Held?

As mentioned above, the workshop is running as a pre-conference training session at cf.Objective(), and will take place from April 20 - 21, 2010 at the conference hotel, which is the Hyatt Regency in Minneapolis, MN.

How Much Does it Cost?

We have made the early-bird price into a permanent discount, so although the original price was listed at $1200 for the two days you can now enroll for just $1000.

How Do I Sign Up?

You can register for the training via cf.Objective()'s registration form.

Can Anyone Attend?

Although the workshop is being offered as a cf.Objective() pre-Conference class, you don't have to attend cf.Objective() in order to enroll. So if you've having trouble getting your boss to pony up for a trip to cf.Objective(), perhaps you can convince him or her to at least send you to these two days of invaluable training.

What Topics Will Be Covered?

Here's a summary of the topics that we'll be covering:

  • Introduction to ORM
  • Introduction to Hibernate
  • Configuring ORM
  • Working with Objects
    • Creating an Object
    • Retrieving an Object / Lists of Objects
    • Updating an Object
    • Deleting an Object
    • Arrays of Objects vs. Queries
  • Mapping Objects
    • Ids and Properties
    • Many-to-One Relationships
    • One-to-Many Relationships
    • Many-to-Many Relationships
    • Formulas
    • Collection Mapping
    • Inheritance
    • Cascade Options
  • Hibernate Internals
    • Hibernate Sessions
    • Session Flushing
      • How It Works
      • How to Control It
    • Working with Transactions
    • Hibernate Object State
      • Transient, Persistent and Detached
      • How Objects Move between States
  • Lazy Loading
    • Overview
    • How it Affects SQL
    • Dealing with Detached Objects
  • Concurrency
  • HQL
    • What is HQL?
    • Basic Queries
    • Criteria / Parameters
    • Joins
    • Pagination
    • Bulk Updates
  • Application Architecture
    • Using a Service Layer with ORM
    • Using an Abstract Service
  • Caching
  • Event Handling
  • DDL (Database) Generation

Truly a Unique Opportunity

Although we do have plans to make the course available at other venues in the future, Mark and I live on opposite sides of the planet, and it just so happens that we'll both be attending cf.Objective() this year. It's likely that future classes will feature either Mark or I as instructors, as it's a rare occurrence that we're both in the same place at the same time, so don't miss this unique opportunity.

Looking for More Information?

I think I've covered most of what you need to know about the course in this post, but if you're looking for even more information about it please visit our web site at

Previous Entries / More Entries