Just a quick little method I thought I would share with everyone. I was working with a ColdFusion ORM entity and I needed to know what field was the primary key. Turns out you can tap into the Session Factory to find this out. This You can also find out the type of the primary key.

#1 by Ben Nadel on 12/21/09 - 11:21 AM
#2 by Dan Vega on 12/21/09 - 11:29 AM
#3 by Raymond Camden on 12/21/09 - 11:46 AM
#4 by John Whish on 12/21/09 - 11:47 AM
ORMGetSessionFactory().getClassMetadata( "EntityName" ).getIdentifierColumnNames()
you get an array of properties which make up the identifier.
I did post some other handy methods here if anyone is interested: http://www.aliaspooryorik.com/blog/index.cfm/e/pos...
#5 by Ben Nadel on 12/21/09 - 11:47 AM
Sorry if I muddied the waters :) Still haven't fully dove into this stuff yet.
#6 by Dan Vega on 12/21/09 - 12:03 PM
@Ben - No problem, it sparked a good conversation and I like you am just trying to learn man.
#7 by Dan Vega on 12/21/09 - 12:08 PM
getIdentifierGenerator(java.lang.String) returns - org.hibernate.id.IdentifierGenerator
getIdentifierPropertyName(java.lang.String) returns - java.lang.String
getIdentifierType(java.lang.String)
returns - org.hibernate.type.Type
#8 by Justice on 12/24/09 - 7:12 PM
Hibernate makes a drastic distinction between properties and columns. Java classes (and CF components) have "properties," while database tables have "columns," and Hibernate is capable of handling very complex mappings between these class properties and database columns. It is important to keep these two words clear and distinct in one's mind when thinking about Hibernate.
For example, the identifier property might be mapped to two columns. And another pair of properties might be mapped to a single column.
Hibernate requires a single identifier property, which can be mapped to either a unicolumn primary key or a multicolumn primary key.
That's why you will see the apparent discrepancy between getIdentifierPropertyName and getIdentifierColumnNames.
Cheers,
Justice