<?xml version="1.0" encoding="utf-8"?>

			<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">

			<channel>
			<title>Brian Kotek: Inversion of Control - Object-Relational Mapping</title>
			<link>http://www.briankotek.com/blog/index.cfm</link>
			<description>Brian Kotek on ColdFusion, Flex, AIR, Java, Groovy, Design Patterns, and Object-Oriented Programming</description>
			<language>en-us</language>
			<pubDate>Fri, 10 Sep 2010 01:38:40 -0700</pubDate>
			<lastBuildDate>Thu, 09 Sep 2010 08:48:00 -0700</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>brian428@briankotek.com</managingEditor>
			<webMaster>brian428@briankotek.com</webMaster>
			<itunes:subtitle></itunes:subtitle>
			<itunes:summary></itunes:summary>
			<itunes:category text="Technology" />
			<itunes:category text="Technology">
				<itunes:category text="Podcasting" />
			</itunes:category>
			<itunes:category text="Technology">
				<itunes:category text="Tech News" />
			</itunes:category>
			<itunes:keywords></itunes:keywords>
			<itunes:author></itunes:author>
			<itunes:owner>
				<itunes:email>brian428@briankotek.com</itunes:email>
				<itunes:name></itunes:name>
			</itunes:owner>
			
			<itunes:explicit>no</itunes:explicit>
			
			
			
			
			
			<item>
				<title>Using ColdFusion ORM and HQL, Part 1</title>
				<link>http://www.briankotek.com/blog/index.cfm/2010/9/9/Using-ColdFusion-ORM-and-HQL-Part-1</link>
				<description>
				
				Now that the Hibernate integration in ColdFusion 9 has been in use for a while, we&apos;re seeing an increasing number of questions on the &lt;a href=&quot;http://groups.google.com/group/cf-orm-dev&quot; target=&quot;_blank&quot;&gt;CF-ORM mailing list&lt;/a&gt;. This isn&apos;t surprising, Hibernate is a vast topic in and of itself, and the CF documentation can really only scratch the surface. There are entire books just dedicated to using Hibernate (my personal favorite being &lt;a href=&quot;http://www.amazon.com/Java-Persistence-Hibernate-Christian-Bauer/dp/1932394885&quot; target=&quot;_blank&quot;&gt;Java Persistence with Hibernate&lt;/a&gt;). 

It&apos;s one thing to look at the documentation and understand the simple use cases, but quite another to actually get into real world application development with Hibernate. With this in mind, I&apos;m going to be posting a few blog entries that explore using CF and Hibernate in some more complex scenarios.

The end result will be a rudimentary blog application, and I&apos;ll post that code in the last blog entry on this topic. But before we get to that, I want to back up and look at how one might approach the design of this application.

Here is a simple UML diagram of the domain model I want to create:

&lt;img src=&quot;http://www.briankotek.com/blog/images/ormblog.png&quot; /&gt;

Contrary to good OO design, I&apos;m not focusing on the behavior of these objects at all due to the fact that this is specifically an ORM example. I am also making the following assumptions, which affected the way the associations were defined, and will drive some later decisions when it comes to loading the objects:

&lt;ul&gt;
&lt;li&gt;A BlogEntry will typically be associated with a few BlogCategories (between one and four, but maybe a few more)&lt;/li&gt;
&lt;li&gt;A large number of BlogEntries (hundreds or thousands) can be associated with a BlogCategory&lt;/li&gt;
&lt;li&gt;A low to moderate number of BlogComments can be associated with a BlogEntry (probably up to a few dozen unless the entry triggers an unusual number of comments)&lt;/li&gt;
&lt;li&gt;Each entity should keep track of when it was created and who created it&lt;/li&gt;
&lt;/ul&gt;

With this in mind, the relationships are defined as follows:

&lt;ul&gt;
&lt;li&gt;One User can be associated with many Entities via the createdBy property&lt;/li&gt;
&lt;li&gt;One BlogCategory can be associated with many BlogEntries&lt;/li&gt;
&lt;li&gt;Many BlogComments can be associated with a BlogEntry&lt;/li&gt;
&lt;li&gt;One BlogEntry can be associated with a BlogComment&lt;/li&gt;
&lt;/ul&gt;

Translated into code, the entities look like this:

&lt;code&gt;js|
component displayname=&quot;Entity&quot; output=&quot;false&quot; mappedsuperclass=&quot;true&quot; accessors=&quot;true&quot;
{
	property name=&quot;id&quot; fieldtype=&quot;id&quot; type=&quot;numeric&quot; ormtype=&quot;int&quot; generator=&quot;native&quot;;
	property name=&quot;dateCreated&quot; type=&quot;date&quot; ormtype=&quot;timestamp&quot;;
	property name=&quot;createdBy&quot; fieldtype=&quot;many-to-one&quot; cfc=&quot;User&quot; fkcolumn=&quot;createdBy&quot;;
}
&lt;/code&gt;

&lt;code&gt;js|
component displayname=&quot;User&quot; extends=&quot;Entity&quot; persistent=&quot;true&quot;
		  output=&quot;false&quot; accessors=&quot;true&quot;
{
	property name=&quot;name&quot; type=&quot;string&quot; ormtype=&quot;string&quot;;
}
&lt;/code&gt;

&lt;code&gt;js|
component displayname=&quot;BlogEntry&quot; extends=&quot;Entity&quot; output=&quot;false&quot; 
		  persistent=&quot;true&quot; accessors=&quot;true&quot;
{
	property name=&quot;title&quot; type=&quot;string&quot; ormtype=&quot;string&quot;;
	property name=&quot;content&quot; type=&quot;string&quot; ormtype=&quot;text&quot;;
	property name=&quot;categories&quot; singularname=&quot;category&quot; fieldtype=&quot;many-to-many&quot; 
  		     cfc=&quot;BlogCategory&quot; linktable=&quot;entry_category&quot; 
  		     fkcolumn=&quot;entryId&quot; inversejoincolumn=&quot;categoryId&quot;;
	property name=&quot;comments&quot; singularname=&quot;comment&quot; fieldtype=&quot;one-to-many&quot;
  		     cfc=&quot;BlogComment&quot; fkcolumn=&quot;entryId&quot; 
  		     orderby=&quot;dateCreated ASC&quot; inverse=&quot;true&quot;;
	
	BlogEntry function init()
	{
		variables.categories = [];
		variables.comments = [];
		return this;
	}	
}
&lt;/code&gt;

&lt;code&gt;js|
component displayname=&quot;BlogCategory&quot; extends=&quot;Entity&quot; output=&quot;false&quot;
		  persistent=&quot;true&quot; accessors=&quot;true&quot;
{
	property name=&quot;name&quot; type=&quot;string&quot; ormtype=&quot;string&quot;;
}
&lt;/code&gt;

&lt;code&gt;js|
component displayname=&quot;BlogComment&quot; extends=&quot;Entity&quot; output=&quot;false&quot;
		  persistent=&quot;true&quot; accessors=&quot;true&quot;
{
	property name=&quot;content&quot; type=&quot;string&quot; ormtype=&quot;text&quot;;
	property name=&quot;blogEntry&quot; fieldtype=&quot;many-to-one&quot; 
 	  	     fkcolumn=&quot;entryId&quot; cfc=&quot;BlogEntry&quot;;  
}
&lt;/code&gt;

As you can see, this is really a tiny amount of code when you consider everything that is going on under the hood. This gives me a solid basis for the application. I can create these objects, set properties and associations, and persist them to the database. But that&apos;s the easy part. I want to go further than the simple use cases.

In the upcoming entries, I&apos;ll look at how to best handle the bi-directional association between BlogEntry and BlogComment, as well as how to automatically set the createdBy and dateUpdated properties in Entity. I&apos;ll also be taking an in-depth look at using HQL for filtering, sorting, and optimizing the way the objects are created to eliminate unnecessary database queries.
				
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>Object-Relational Mapping</category>
				
				<pubDate>Thu, 09 Sep 2010 08:48:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2010/9/9/Using-ColdFusion-ORM-and-HQL-Part-1</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>More on CF9 ORM Relationships</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/12/21/More-on-CF9-ORM-Relationships</link>
				<description>
				
				My entry late last week on &lt;a href=&quot;http://www.briankotek.com/blog/index.cfm/2009/12/16/Bidirectional-Association-Management-in-ColdFusion-9-ORM&quot; target=&quot;_blank&quot;&gt;association management methods&lt;/a&gt; prompted a number of comments. I was going to add another comment but this became quite long so instead I&apos;m adding another blog entry.

The point of my last post was to talk about bidirectional relationships, particularly a one-to-many/many-to-one between two entities. Hibernate (and, thus, the CF9 ORM) has the ability to specify an &quot;inverse&quot; attribute on your relationship. To better show why you usually want to do this, let&apos;s look at an example.
				 [More]
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>OOP CF</category>
				
				<category>Object-Relational Mapping</category>
				
				<pubDate>Mon, 21 Dec 2009 13:07:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/12/21/More-on-CF9-ORM-Relationships</guid>
				
				
			</item>
			
		 	
			
			
			<item>
				<title>Bidirectional Association Management in ColdFusion 9 ORM</title>
				<link>http://www.briankotek.com/blog/index.cfm/2009/12/16/Bidirectional-Association-Management-in-ColdFusion-9-ORM</link>
				<description>
				
				And to follow up on my recent pledge to start blogging further about ORM, lets jump right into a recent topic. A thread on the CF-ORM mailing list brought up the topic of &lt;a href=&quot;http://groups.google.com/group/cf-orm-dev/browse_thread/thread/4320cc207bc8df53?hl=en&quot; target=&quot;_blank&quot;&gt;dealing with a bidirectional relationship&lt;/a&gt;.
				 [More]
				</description>
				
				
				<category>ColdFusion</category>
				
				<category>OOP CF</category>
				
				<category>Object-Relational Mapping</category>
				
				<pubDate>Wed, 16 Dec 2009 10:36:00 -0700</pubDate>
				<guid>http://www.briankotek.com/blog/index.cfm/2009/12/16/Bidirectional-Association-Management-in-ColdFusion-9-ORM</guid>
				
				
			</item>
			
		 	
			</channel></rss>