Null Pointer Error with HQL? Check for this...

This post is more than 2 years old.

Yesterday I was writing what I thought to be some pretty simple HQL:

var res = ormExecuteQuery("from user where email = :email", {});

Unfortunately I kept getting the Java Lazy Cop Out error (sorry, I mean the Null Pointer Error):

java.lang.NullPointerException at org.hibernate.param.NamedParameterSpecification.bind( at org.hibernate.loader.hql.QueryLoader.bindParameterValues( at org.hibernate.loader.Loader.prepareQueryStatement( at org.hibernate.loader.Loader.doQuery( at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections( at you get the idea.

The error seemed to imply something wrong with my named parameter, email. I did a dump on the arguments scope to ensure email existed and it did. So what was it? Turns out I had not defined email as a property of my entity! Surely the error could have recognized that. Once I actually added email (and ran an ormReload - don't forget ColdFusion caches such definitions), it worked. I tweeted this last night and Joe Rinehart pointed you get the same issue if your case in the HQL statement does not match the case defined in your entity. That's correct too. Changing my code like so:

var res = ormExecuteQuery("from user where eMail = :email", {});

Also threw an NPE as well. sigh So - is this a ColdFusion or Hibernate bug? I'm not sure. If this is how Hibernate throws the error, than ColdFusion can't do much about it. I'm filing a bug anyway just to be sure. I know that Adobe did a lot of work in ColdFusion 9.0.1 to improve the error messages from ORM issues so if this can be updated as well, it would help.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Andrew Scott posted on 3/29/2011 at 9:44 PM

Have you tried it this way?

var res = ormExecuteQuery("from user u where u.eMail = :email", {});

HQL does require it to be written this way.

Comment 2 by Raymond Camden posted on 3/29/2011 at 9:47 PM

What in particular? Do you mean adding the table alias? If so - I disagree. I've never seen aliases required before.

Comment 3 by Andrew Scott posted on 3/29/2011 at 9:52 PM

Interesting, every HQL example I have seen is aliased. If I try to use it without an Alias I get either this error, or I more commonly I get

Error Type: Application : [N/A]
Error Messages: Error while executing the Hibernate query.
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: left near line 1, column 36 [FROM category where parent=1 order by left]

However if it is aliased it will work fine.

Comment 4 by Raymond Camden posted on 3/29/2011 at 9:55 PM

Simplify a bit - just to make things easier. Remove the order by and see if you still get an error.

Comment 5 by Andrew Scott posted on 3/29/2011 at 10:01 PM

Your example or mine?

Comment 6 by Raymond Camden posted on 3/29/2011 at 10:04 PM

Well, yours. I think you are saying that you think aliases are required. I'm saying they are not (but could be wrong). You mentioned getting an error in your last comment and I suggested making your HQL a bit simpler to see if we could figure out what the issue is.

Comment 7 by Brian Paulson posted on 4/7/2011 at 6:46 AM

Check your column name and case. I was having the same issue and the column was named paydate and I was using payDate in my query and was getting the same error and fixing the case cleared up the Null Pointer Exception.

Comment 8 by Ron West posted on 3/6/2012 at 9:29 AM


Your suggestion was spot on. I was having this issue and as soon as I matched up the case from my bean - bingo. Thanks!

Comment 9 by Victor posted on 11/8/2012 at 5:16 AM

I came across this error. The cause is using upper case in property name.
I've come to conclusion that upper case shouldn't be used in ColdFusion ORM. Otherwise you can get problems later.