ORM gotcha: Hibernate reserved words — sebduggan.uk Skip to main content

ORM gotcha: Hibernate reserved words

Typically, the very first time I tried to use CF9's ORM, I ran into a bizarre problem which had me scratching my head for hours...

The setup was this: a table in my SQL database called "member". A member.cfc object with the following code:

component output="false" persistent="true" { property name="memberid" fieldtype="id"; property name="firstname"; property name="lastname"; }

And a test page which called it:

<cfscript> members = EntityLoad("member"); writedump(members); </cfscript>

Running this page always gave the following error:

unexpected token: member near line 1, column 6 [from member]

However, if I gave the EntityLoad() function more arguments, for instance:

members = EntityLoad("member", {});

...it worked perfectly.

After a lot of head-scratching and seeking of help on Twitter (thanks @aliaspooryorik) and Stack Overflow (thanks Henry), I had the idea that "member" might be some sort of reserved word in Hibernate. So I changed the table and component names to "user" -- and everything worked exactly as it should.

My guess is that it works fine if in the generated HQL query there's a WHERE clause following the SELECT FROM member; but if you just have the basic EntityLoad("member") then it doesn't have this WHERE clause, and so the reserved word "member" gets seen as an HQL keyword.

I guess I was just unlucky that my very first attempt at ORM ran into this problem; does anyone know of any other table/object names I should steer clear of?