|
Sponsored Links
Resources
Enterprise Java Research Library
Get Java white papers, product information, case studies and webcasts
|
News
News
News
|
Messages: 8
Messages: 8
Messages: 8
Printer friendly
Printer friendly
Printer friendly
Post reply
Post reply
Post reply
XML
XML
XML
|
 |
JPA implementation patterns
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
Advanced 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!
|
|
Message #311690
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: JPA implementation patterns
In only slightly related fashion, Joseph Ottinger smiled at Vincent Partington's willingness to refer to himself in the second person...
|
|
Message #311699
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: JPA implementation patterns
In only slightly related fashion, Joseph Ottinger smiled at Vincent Partington's willingness to refer to himself in the second person...
Third? :)
|
|
Message #311713
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: JPA implementation patterns
@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. ;-)
|
|
Message #311714
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: JPA implementation patterns
I like the trick with the entityClass for the code in the base DAO, but for the specific DAO, I don't really see the use of this:
public class JpaOrderDao extends JpaDao<Integer, Order> implements OrderDao { public List<Order> findOrdersSubmittedSince(Date date) { Query q = entityManager.createQuery( "SELECT e FROM " + entityClass.getName() + " e WHERE date >= :date_since"); q.setParameter("date_since", date); return (List<Order>) q.getResultList(); } }
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 ;)
|
|
Message #311717
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: JPA implementation patterns
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
|
|
Message #311718
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: JPA implementation patterns
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.
|
|
Message #311728
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Re: JPA implementation patterns
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
|
|
Message #313306
Post reply
Post reply
Post reply
Go to top
Go to top
Go to top
|
 |
Hades easing JPA development
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
|
|
 |
New content on TheServerSide.comNew content on TheServerSide.comNew content on TheServerSide.com |
 |
 |
Reza Rahman continues to explore the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6.
(January 21, Article)
Ted Neward is an independent consultant specializing in high-scale enterprise systems, and an authority in Java and .NET technologies. He is the author and co-author of several books, including Effective Enterprise Java. At TheServerSide Java Symposium in March, he will be presenting sessions on pragmatic architecture, ECMAScript and Scala.
(January 15, Article)
Now that Oracle is absorbing Sun Microsystems, there mixed views on what should come of the Java Community Process (JCP). While some say Oracle should become the new steward of Java and keep the JCP much as it was, others argue that it may be time to open-source this widespread language.
(November 24, Article)
Reza Rahman explores the features of the proposed JSR 299, Contexts and Dependency Injection for Java EE (CDI). When approved, it promises to be a key feature of Java EE 6.
(November 2, Article)
SAML is an XML-based standard for exchanging authentication and authorization data between security domains. The single most important problem that SAML was created to solve is the Web browser Single Sign-On problem. Many organizations are debating whether to stay with version 1.1 or move to 2.0. This article makes observations about both options.
(September 28, Article)
Joe Ottinger takes a look at how people learn, and applies it to the practice of programming. He notes that understanding how people learn is an essential part of working in a programming team.
(September 22, Article)
Stephen Maryka gave us an article about the Asynchronous Web and posed a number of questions that get examined like an approach to delivering Asynchronous Web capabilities through extensions to existing Java EE technologies.
(July 14, Article)
JavaServer Faces Flex goal is to provide users capability in creating standard Flex components, part of flexSDK which is open sourced through MPL license, as normal JSF components. This article by Ji Hoon Kim will provide an overview of creating a simple multilingual JSF page consisting of JSF Flex tags.
(June 29, Article)
In this session Jeff explores the key characteristics of successful SOA projects. He covers some of the patterns, and anti-patterns, tool sets, and strategies that he himself learned the hard way. Last, he provides a strategy and blueprint for achieving a high likelihood of success in your SOA project.
(June 23, Tech Talk)
Ari Zilka, CTO of Terracotta, Inc., talks about the new features in Terracotta 3.1, announced during JavaOne and available now.
(June 15, Tech Talk)
In this Tech Talk, Josh Long explores an integration challenge using Spring Integration and walks through the implementation, employing and expanding on the basic patterns of Enterprise Application Integration to tie together components into a function integration solution, and then demonstrates how Spring Integration helps address the integration requirements.
(June 15, Tech Talk)
In this Tech Talk, David Geary teaches you: The basics of Google Web Toolkit; How to implement Ajax-enabled applications in Java; Internationalization; Hooking into the browser history mechanism; Remote procedure calls.
(June 4, Tech Talk)
Jon Kern discusses the best architecture/technical solutions and ensure that they are repeated by all developers. By tackling the architecture up-front in a serial manner, subsequent parallel development will be much more manageable and predictable.
(May 28, Tech Talk)
This keynote describes the frustrations of modern knowledge workers in their quest to actually get some work done, and solutions for how to guard yourself against all those distractions. Neal Ford talks about environments, coding, acceleration, automation, and avoiding repetition as ways to defeat the misguided attempts to sap your ability to produce good work.
(May 26, Tech Talk)
Gil demonstrates how new, aggressive uses of already abundant compute capacity by common applications offer competitive value for application designers.
(May 21, Tech Talk)
Chris Keene introduces WaveMaker as a new way to automate the ability to generate Hibernate classes in order to more quickly bring OR mapping into an application.
(May 19, Article)
Mastering EJB was one of the original and most influential EJB books in the industry. Mastering EJB III now returns with two new expert co-authors, updated for EJB 2.1 and 30% new chapters including security, integration, best practices, open source, and more.
(Book PDF Download)
The Application Server Matrix is a detailed listing of J2EE vendors and their application server products, with information on latest version numbers, J2EE spec support and licensing, pricing, platform support, and links to product downloads and reviews.
(Application Server Comparison Matrix)
|
|