Yesterday I was writing what I thought to be some pretty simple HQL:
var res = ormExecuteQuery("from user where email = :email", {email=arguments.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(NamedParameterSpecification.java:67) at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:567) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612) at org.hibernate.loader.Loader.doQuery(Loader.java:717) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270) 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", {email=arguments.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.
Archived Comments
Have you tried it this way?
var res = ormExecuteQuery("from user u where u.eMail = :email", {email=arguments.email});
HQL does require it to be written this way.
What in particular? Do you mean adding the table alias? If so - I disagree. I've never seen aliases required before.
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.
Simplify a bit - just to make things easier. Remove the order by and see if you still get an error.
Your example or mine?
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.
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.
Brian,
Your suggestion was spot on. I was having this issue and as soon as I matched up the case from my bean - bingo. Thanks!
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.