Discussions

After discovering that there was a lack of documentation on how to use JPA in real-life scenario's, Vincent Partington has written a series of blogs about the JPA implementation patterns he discovered while writing JPA code. To wrap up the series, he has made an overview of all the patterns that have been discussed for easy reference.
Basic patterns

If there is one thing to take away from this series is that it is pays off to really look into the details of JPA. Even though the promise of an abstraction layer invites you to take ORM for granted. Incorrect database usage is still Java EE performance problem #1, so there is a lot to gain here!

Since this query is already specific for the Order entity, maybe entityClass.getName() doesn't add that much. Just writing the actual class name directly makes the query easier to read and as far as I can see doesn't cost you anything in terms of flexibility or power.
Of course, if there is any benefit here that I missed, please enlighten me ;)

The above code is refactor safe. When you change the classname you do not have to go and change every single query that references that class. That said, ide's like intellij idea are smart enough to also rename references to a class in queries. It even has syntax asist for your queries, that coincidentally doesnt work when you use the FROM " + entityClass.getName() + " idiom. Thats why i dont use it anymore these days, but if your stuck in an eclipse based environment it makes perfect sense

The above code is refactor safe. When you change the classname you do not have to go and change every single query that references that class.

I hear you and you do have a point there. On the other hand, the query contains more references to the class like a reference to the "date" property which still causes problems. Maybe if java had such a thing as method literals, but it hasn't and thus the query is still not really refactor safe.

Yeah, I'm facing this issue now and am forced into building my own reflection based query builder. I wish JPA would include some refactor safe facilities so you would have to refactor all the queries as well. It's hard enough building dynamic queries not having a decent query builder, now we also suffer from all the maintenance that has to be done. Also, it would be nice if the criteria building api which will be a part of JPA 2 would allow to build native queries using native query constructs, since not everything can be modeled using JPA and a nice native query builder for the side cases would be great.
Ilya

Hey guys,
are you aware of the open source project Hades [1]. It acts as abstraction layer on top of JPA and Spring and supports developers on the tedious work of data access layers with Spring. It implements common best practices around generic DAOs [2] and allows query execution by simply defining methods in an interface. Saves a lot of time and effort. Feel free to check it out and let me know what you think.
Ollie
Hades project lead
[1] - http://hades.synyx.org
[2] - http://www.ibm.com/developerworks/java/library/j-genericdao.html

@Joseph: Yeah, if it says "posted by Vincent Partington" at the top then referring to myself in the third person seems a bit silly. I reckoned you would post it under your own name as you did when you posted the Top 10 Java EE performance problems so I thought I'd help you edit it. Anyway, feel free to change it to refer to myself as "I".
Argh, even talking about this is silly. ;-)

What I am searching for is adolescent humans of access in our community pass4sure 640-802. I am alive on ambience up an Advisory Council that will serve as consultants and connectors for the project pass4sure F50-531. I would adulation to acquisition a (or several) motivated, affiliated adolescent humans from the association who affliction about the affair of advantageous sexuality pass4sure 1Y0-A05. Adolescent parents would be a plus! Part of the access that Real Life. Real Talk. takes is that we charge non-traditional partners, including the business community, to accouterment this issue.

TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations technology projects - with its network of technology-specific websites, events and online magazines.