Listing Coldfusion ORM entities programatically
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>
This 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.
Comments