Interface is meaningless with orm entity?

8 views
Skip to first unread message

Henry Ho

unread,
Oct 20, 2009, 9:56:14 PM10/20/09
to cf-orm-dev
Since an orm entity needs to point to a cfc to get the metadata for
defining relationships, does it mean using Interface for flexibility
becomes meaningless?

Shannon Hicks

unread,
Oct 20, 2009, 11:03:35 PM10/20/09
to cf-orm-dev
I don't think so. You still can implement your own methods, so having:

I_person {
public function getFullName()
public function getMailingAddress()
...
}

employee implements person { ... }
client implements person { ... }

Would still have the same benefits of anything else that implemented
an interface, no? I mean, it doesn't matter if the methods are
getters, setters or custom-built, they're still just methods.

Shan

Henry Ho

unread,
Oct 21, 2009, 2:15:47 PM10/21/09
to cf-orm-dev
Use of Interface make code less coupled to a concrete class/cfc.
However, the consumer of the Interface also need to point to a
concrete cfc to define an orm relationship.

e.g.

// without ORM
property IContact contact;

// with ORM, it'll become...
property name="contact" type="IContact" fieldtype="xxx-to-yyy"
cfc="ConcreteContact1";

Do you see how even though the type is IContact, it is actually
coupled to ConcreteContact1.cfc due to the ORM metadata?

Regards,
Henry

Tony Nelson

unread,
Oct 21, 2009, 2:38:39 PM10/21/09
to cf-orm-dev
You could manage your relationships inside the Hibernate mapping files
rather than in your CFCs. That way you keep the implementation details
(which CFC to point to) out of your entities.

-Tony

Henry Ho

unread,
Oct 21, 2009, 2:50:26 PM10/21/09
to cf-orm-dev
Good point, I thought about that as well, but I guess metadata is much
faster to define the relationship. Trade-off's...

Henry

Tony Nelson

unread,
Oct 21, 2009, 3:06:05 PM10/21/09
to cf-orm-dev
Since I'm rather new to Hibernate syntax, I've found it's easiest to
define the mappings inside my CFCs to generate the Hibernate mapping
file, remove the mapping details from the properties in the CFC, and
then just use mapping file going forward. Plus, there's some pretty
nice functionality inside Hibernate that you can't directly set
through simple CFC mappings, such as data filters.

-Tony

Henry Ho

unread,
Oct 21, 2009, 3:09:30 PM10/21/09
to cf-or...@googlegroups.com
Tony, can you pls make a blog post and maybe teach us how to do it?  It sounds really an awesome way to generate the mapping xml!

Henry

John Whish

unread,
Oct 21, 2009, 3:19:56 PM10/21/09
to cf-or...@googlegroups.com
this.ormsettings.savemapping = true

Specifies whether the generated Hibernate mapping file has to be saved to disc. If you set the value to true, the Hibernate mapping XML file is saved with the filename "CFC name".hbmxml in the same directory as the CFC.

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSED380324-6CBE-47cb-9E5E-26B66ACA9E81.html

Tony Nelson

unread,
Oct 21, 2009, 3:22:06 PM10/21/09
to cf-orm-dev
Um... I don't think it really deserves a blog post. All you need to do
is set this.ormSettings.saveMapping = true in your Application.cfc.
Hibernate will then create a corresponding [Entity].hbmxml for each
entity it finds. You can then take that file and do whatever you want
with it, like moving it to a /config directory and combining it with
other mapping files. If you still want some help I could go into more
detail, but there's really not much to it.

-Tony

On Oct 21, 2:09 pm, Henry Ho <henryho...@gmail.com> wrote:
> Tony, can you pls make a blog post and maybe teach us how to do it?  It
> sounds really an awesome way to generate the mapping xml!
>
> Henry
>

Henry Ho

unread,
Oct 21, 2009, 3:24:22 PM10/21/09
to cf-or...@googlegroups.com
Cool, that's easy.  Then how to tell CF to use those XML on the next run?

Thanks,

Henry

Tony Nelson

unread,
Oct 21, 2009, 3:32:04 PM10/21/09
to cf-orm-dev
You don't have to tell ColdFusion to use them.

"After loading the Hibernate configuration, all the mapping files
(*.hbmxml) in the application folder and its mapped folders are loaded
and added to the configuration."

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSB51B3786-8E55-4a72-ABDB-5707B9A853D9.html

-Tony

On Oct 21, 2:24 pm, Henry Ho <henryho...@gmail.com> wrote:
> Cool, that's easy.  Then how to tell CF to use those XML on the next run?
>
> Thanks,
>
> Henry
>
> On Wed, Oct 21, 2009 at 12:19 PM, John Whish <john.wh...@googlemail.com>wrote:
>
> > this.ormsettings.savemapping = true
>
> > Specifies whether the generated Hibernate mapping file has to be saved to
> > disc. If you set the value to true, the Hibernate mapping XML file is saved
> > with the filename "CFC name".hbmxml in the same directory as the CFC.
>
> >http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSED380324-6CBE...
>
>

Henry Ho

unread,
Oct 21, 2009, 3:34:25 PM10/21/09
to cf-or...@googlegroups.com
Awesome, thank you very much guys!

Henry

John Whish

unread,
Oct 21, 2009, 3:35:04 PM10/21/09
to cf-or...@googlegroups.com
Henry, ColdFusion will just find them. If it doesn't, then ColdFusion will just generate them anyway but keep them in memory. The savemapping tells ColdFusion to save the in-memory version to disk. It's definately worth using the config files as you can use some extra hibernate features.

John Whish

unread,
Oct 21, 2009, 3:35:34 PM10/21/09
to cf-or...@googlegroups.com
Ack, Tony beat me to it :D

Henry Ho

unread,
Oct 21, 2009, 3:37:58 PM10/21/09
to cf-or...@googlegroups.com
what are some of the "extra features" that are useful to you?  Where can I find the complete list?

Thanks!
Henry

John Whish

unread,
Oct 21, 2009, 3:42:15 PM10/21/09
to cf-or...@googlegroups.com
To be honest, I'm still learning this stuff so can't give you a comprehensive answer, but Tony Nelson wrote a good example of a useful feature using hibernate's filtering to do soft deletes:

http://bears-eat-beets.blogspot.com/2009/10/hibernate-data-filters.html

HTH

Tony Nelson

unread,
Oct 21, 2009, 3:43:19 PM10/21/09
to cf-orm-dev
Short answer? https://www.hibernate.org/

If you want an example, I recently posted about data filters.

http://bears-eat-beets.blogspot.com/2009/10/hibernate-data-filters.html

On Oct 21, 2:37 pm, Henry Ho <henryho...@gmail.com> wrote:
> what are some of the "extra features" that are useful to you?  Where can I
> find the complete list?
>
> Thanks!
> Henry
>

Tony Nelson

unread,
Oct 21, 2009, 3:45:09 PM10/21/09
to cf-orm-dev
You beat me to my own post? Bah.

-Tony

On Oct 21, 2:43 pm, Tony Nelson <tonynelso...@gmail.com> wrote:
> Short answer?https://www.hibernate.org/

John Whish

unread,
Oct 21, 2009, 3:49:35 PM10/21/09
to cf-or...@googlegroups.com
Sorry Tony, I was trying to give you give you credit by saying what a great example it was.

Henry Ho

unread,
Oct 21, 2009, 3:51:37 PM10/21/09
to cf-or...@googlegroups.com
I don't recalling reading your post before.  Have you subscribed your blog to http://www.coldfusionbloggers.org/ or http://feeds.adobe.com ?

Henry

Tony Nelson

unread,
Oct 21, 2009, 3:54:43 PM10/21/09
to cf-orm-dev
Nope. I'm just a rogue blogger.

-Tony

On Oct 21, 2:51 pm, Henry Ho <henryho...@gmail.com> wrote:
> I don't recalling reading your post before.  Have you subscribed your blog
> tohttp://www.coldfusionbloggers.org/orhttp://feeds.adobe.com?
>
> Henry
>
> On Wed, Oct 21, 2009 at 12:43 PM, Tony Nelson <tonynelso...@gmail.com>wrote:
>
>
>
> > Short answer?https://www.hibernate.org/

Mark Mandel

unread,
Oct 21, 2009, 4:48:41 PM10/21/09
to cf-or...@googlegroups.com
For convenience sake, I wrote a ColdFusion Builder Extension to right click on a CFC and output a simple stub for CFC mappings, that works out some basic meta data for you and writes (often a cleaner) XML mapping file than ColdFusion will do:

http://genormmapping.riaforge.org/

Note - this doesn't reverse engineer all your annotations -> a mapping file. This gives you a stub to work from if you have properties defined, and will set those up for you.  So it does some bits, but not all.

That being said, there is some parsing capabilities built in, and I'm happy to take contributions on that area, the code is nothing complex.

Mark
--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

Reply all
Reply to author
Forward
0 new messages