ColdFusion 9 ORM Set-up

ColdFusion 9 supports ORM natively via the Hibernate framework. From the horses mouth, this is what it means:

Object relational mapping (ORM) is a programming framework that allows you to define a mapping between application object model and the relational database.

In an object model, the application objects are not aware of the database structure. Objects have properties and references to other objects. Databases consist of tables with columns that maybe related to other tables. ORM provides a bridge between the relational database and the object model. By using ORM, you can access and update data entirely using the object model of an application. ORM provides features such as:

  • Database vendor independence;
  • Caching;
  • Concurrency;
  • Performance optimization

- Developing Applications ADOBE® COLDFUSION9

Again for simplicity, I am going to use the Microsoft Adventureworks database. Assuming you have MS SQL Server installed and the Adventureworks database running, accessing data from via ColdFusion using Hibernate is pretty straight forward. Create a datasource “adventureworks” in the CF Admin pointing to your “Adventureworks” database.

Fire up Dreamweaver or ColdFusion builder and create a new site. The most important thing is to have your Application.cfc in place to enable ORM, like so:

1.) Enable ORM via Application.cfc

component
{
THIS.name = “awORM”;
THIS.ormenabled = true;
THIS.ormsettings = {datasource=’adventureworks’};
}

Like everything “ColdFusion”, the code snippet is self explanitory. I use the “script style” component as a personal preference, but a “tag style” approach is exactly the same thing.

2.) Creating your first component mapping

Create a component file called Contact.cfc with the following attributes and properties:

component table=”Contact” schema=”Person” entityname=”Contact” persistent=”true” {
property name=”ContactID” fieldtype=”id” column=”ContactID” ormtype=”integer” generator=”native”;
property name=”NameStyle” column=”NameStyle” ormtype=”string”;
property name=”Title” ormtype=”string”;
property name=”FirstName” ormtype=”string”;
property name=”MiddleName” ormtype=”string”;
property name=”LastName” ormtype=”string”;
property name=”EmailAddress” ormtype=”string”;
}

I’m using only a subset of the data, not every column in the table.

3.) Create a new page called testcontacts.cfm

Add the following lines:

<cfset myContact = entityLoad(“Contact”, 1)>
<cfdump var=”#myContact#”>

This loads the Contact from your database with the “ContactID” of 1.

*** Note: The first time you try to run the code, for whatever reason, you might get a ColdFusion error page saying the something is wrong with the “mapping”. Simply restart you ColdFusion service, and run the page again.

Looking at the “cfdump” output, expand the “METHODS” section. You will notice that ColdFusion has generated implicet “getters” and “setter” methods for you. To me this is the bargain of the month.

743 Comments to “ColdFusion 9 ORM Set-up”

  1. loestrin 24 coupon 25 August 2011 at 2:18 am #

    Some really choice blog posts on this internet site , saved to bookmarks .

  2. loestrin 24 coupon 25 August 2011 at 2:37 am #

    I got what you mean , saved to favorites , very nice site.

  3. tinnitus remedies 25 August 2011 at 2:39 am #

    Have you ever considered publishing an ebook or guest authoring on other websites? I have a blog centered on the same subjects you discuss and would love to have you share some stories/information. I know my readers would appreciate your work. If you’re even remotely interested, feel free to send me an email.

  4. loestrin 24 coupon 25 August 2011 at 2:56 am #

    I believe other website proprietors should take this web site as an example , very clean and great user genial pattern .

  5. loestrin 24 coupon 25 August 2011 at 3:16 am #

    This site is my breathing in, really great design and style and perfect articles .

  6. loestrin 24 coupon 25 August 2011 at 3:36 am #

    I besides think so , perfectly composed post! .

  7. electricians lancaster pa 25 August 2011 at 3:42 am #

    I really like that. You touched my heart!

  8. loestrin 24 coupon 25 August 2011 at 3:56 am #

    Rattling great visual appeal on this website , I’d value it 10 10.

  9. loestrin 24 coupon 25 August 2011 at 4:16 am #

    I am glad to be a visitor of this stark web site! , appreciate it for this rare info ! .

  10. chenbingy 25 August 2011 at 4:20 am #

    Perfect jean- Recently I purchased my first pair of True Religions. I love the first pair so much that I ordered a second pair. You have to try them… once you do, you will never put on any other pair of para.

  11. loestrin 24 coupon 25 August 2011 at 4:35 am #

    I am glad to be a visitor of this utter web site! , regards for this rare information! .

  12. Sean Desrosiers 25 August 2011 at 4:45 am #

    Hey, Nice work! This is my first time i visit here. I discovered so numerous fascinating stuff in your weblog.

  13. computer consulting los angeles 25 August 2011 at 4:51 am #

    I’m impressed, I must say.

  14. loestrin 24 coupon 25 August 2011 at 4:54 am #

    I conceive you have remarked some very interesting details , thanks for the post.

  15. Isis Hagelgans 25 August 2011 at 5:03 am #

    Greetings! This is my first comment here so I just wanted to give a quick shout out and say I genuinely enjoy reading your posts. Can you recommend any other blogs/websites/forums that go over the same topics? Thanks a lot!

  16. loestrin 24 coupon 25 August 2011 at 5:13 am #

    I always was concerned in this topic and stock still am, regards for posting .

  17. loestrin 24 coupon 25 August 2011 at 5:32 am #

    Deference to website author , some great entropy.

  18. loestrin 24 coupon 25 August 2011 at 5:52 am #

    I like this post, enjoyed this one thankyou for putting up.

  19. loestrin 24 coupon 25 August 2011 at 6:10 am #

    Real informative and great bodily structure of articles , now that’s user friendly (:.

  20. loestrin 24 coupon 25 August 2011 at 6:30 am #

    I always was interested in this topic and stock still am, thankyou for putting up.

  21. loestrin 24 coupon 25 August 2011 at 6:48 am #

    Very interesting topic , appreciate it for putting up.

  22. loestrin 24 coupon 25 August 2011 at 7:06 am #

    I went over this internet site and I believe you have a lot of great info , saved to my bookmarks (:.

  23. loestrin 24 coupon 25 August 2011 at 7:25 am #

    I believe this site holds very great written written content blog posts.

  24. durable labels 25 August 2011 at 7:27 am #

    Nice post. I learn one thing on different blogs everyday. It will always be stimulating to read content from different writers and practice just a little something from their blog.

  25. computer miami 25 August 2011 at 7:27 am #

    After studying a few of the weblog posts in your web site now, and I truly like your method of blogging. I bookmarked it to my bookmark web site list and will probably be checking again soon. Pls check out my site as effectively and let me know what you think.

  26. Alexander Stöckel 25 August 2011 at 7:59 am #

    As I website owner I believe the subject matter here is really excellent , regards for your efforts.

  27. rtyecript 25 August 2011 at 8:16 am #

    I really liked the article, and the very cool blog

  28. Alexander Stöckel 25 August 2011 at 8:19 am #

    This internet site is my breathing in, real great style and perfect content .

  29. Alexander Stöckel 25 August 2011 at 8:39 am #

    I like this website because so much useful stuff on here : D.

  30. discount ugg boots 25 August 2011 at 8:49 am #

    I think you are really very close on your opinion. Anyways keep it up and keep continue with your valuable thoughts. In the near upcoming future.

  31. ugg shoes 25 August 2011 at 8:56 am #

    This is a wonderful article, I located your weblog researching bing for a related subject matter and came to this.

  32. Alexander Stöckel 25 August 2011 at 8:58 am #

    Would love to perpetually get updated great website ! .

  33. Macomb Community 25 August 2011 at 9:09 am #

    There is noticeably a bundle to know about this. I assume you manufactured certain good factors in attributes also.

  34. Alexander Stöckel 25 August 2011 at 9:18 am #

    This web site is my inspiration , rattling great layout and perfect subject matter.

  35. Alexander Stöckel 25 August 2011 at 9:39 am #

    Perfect work you have done, this website is really cool with fantastic info .

  36. ubuntu studio 25 August 2011 at 9:45 am #

    hello there and thank you for your info – I have definitely picked up anything new from right here. I did however expertise several technical points using this website, as I experienced to reload the website lots of times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I am complaining, but slow loading instances times will often affect your placement in google and could damage your quality score if ads and marketing with Adwords. Well I am adding this RSS to my email and could look out for a lot more of your respective intriguing content. Ensure that you update this again soon..

  37. Alexander Stöckel 25 August 2011 at 9:58 am #

    I reckon something really special in this internet site .

  38. Table Saw review 25 August 2011 at 10:12 am #

    Hi there would you mind letting me know which web host you’re using? I’ve loaded your blog in 3 different internet browsers and I must say this blog loads a lot faster then most. Can you suggest a good internet hosting provider at a fair price? Cheers, I appreciate it!

  39. Alexander Stöckel 25 August 2011 at 10:18 am #

    Real excellent visual appeal on this internet site , I’d rate it 10 10.

  40. Alexander Stöckel 25 August 2011 at 10:38 am #

    I want reading and I conceive this website got some truly useful stuff on it! .

  41. Alexander Stöckel 25 August 2011 at 10:57 am #

    I really like your writing style, wonderful information, thanks for posting : D.

  42. Buy Cheap Software 25 August 2011 at 11:01 am #

    Unquestionably believe that which you said. Your favorite reason seemed to be on the internet the simplest thing to be aware of. I say to you, I definitely get annoyed while people consider worries that they just don’t know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks

  43. Alexander Stöckel 25 August 2011 at 11:16 am #

    Thank you for sharing with us, I conceive this website really stands out : D.


Leave a Reply