Listing Coldfusion ORM entities programatically

posted by Chris on Apr 11, 2011 at 12:20

When you write an application It's a fair to assume you know what entities your dealing with, after all you've either written them yourself or your coding to extend an existing application.  Recently though i've been mentally tossing about an idea for a library that can automatically create some services for your orm entites, with the idea that you can just drop it into an orm enbaled ColdFusion application and it will create them for you with a minimum of configuration.

 

To do this i need to be able to list the entities that the application (or its underlying hibernate instance) is currently managing.  However theres no ormListEntites() or similar function that i can find, but with access to the hibernate session factory through ormGetSessionFactory() you can get a list of entities.

<cfscript>
ormClassMetaData = ORMGetSessionFactory().getAllClassMetadata();
ormClassNames = listToarray(structKeyList(ormClassMetaData));
writeDump(ormClassNames);
</cfscript>

 

orm-entity-listThis will get you an array of entity class names that you can then play with and works with Adobe ColdFusion and Railo's implementation of ORM because they both use hibernate under the covers. 

 

 

Its also worth taking a look at the metadata thats returned for each class from ORMGetSessionFactory().getAllClassMetadata(). You can list property names and types, identifier property name and generator, table and column names.  

 

 

Categories:

Comments

Mark Gregory on Apr 14, 2011 at 00:34
I have been looking for a way to list all entities, for a quick reference of what is going on in some cases. This is super cool, thanks!