Tuesday, September 04, 2007

High Quantum Leap?

I am new to JPA and discovered today that HQL is not JPQL. This sounds pretty obvious but the circumstances when I was reminded this cruel reality were puzzling.

First let's start with my mistake! I wrote something like this:

FROM Magazine WHERE title = 'JDJ'

instead of writing that:

SELECT x FROM Magazine x WHERE x.title = 'JDJ'

i.e. HQL instead of JPQL.

You might think that I must be a lousy tester to release code that does not work but the trick is that it was working fine and passing the integration tests.

The issues was that the JPA provider I am using, Hibernate, was not running in strict mode hence was joyfully accepting the HQL queries. Everything was fine in the integration tests run on Jetty but when deployed on JBoss, where a strictly configured Hibernate was used as the JPA provider, all hell was breaking loose.

So conclusion one is that yes, I am a lousy tester: always target the same platform for your integration tests than for your deployments. There are simply too many provided runtime dependencies in an application server to take any chance with them.

And conclusion two is more an open question about the value of standardized Java API built on top of existing proprietary industry standards. Some success exist, like JCR, which is quite an achievement in the complex matter of unifying access to CMS implementations. But I must admit that one could find JPA an off-putting keyhole on Hibernate, spread with tricky drawbacks.

I want to believe that, the same way JAXP started as a gloomy reduction of the capacities of Crimson and Xalan behind wacky factories and ended as a convenient way to unify XML coding in Java, JPA will evolve towards a bright future.


zepag said...

Indeed, next version of JPA should finally include a Criteria API.

Though if you use spring(no doubt about that ;) ), Krank is an interesting project to look at mainly for its Criteria DSL for JPA.


David Dossot said...

Thanks for the pointer to Krank!

And, of course, yes: Spring-a-Ding-Ding is in use ;-)