![]() This scenario suffers from an increase of the loading time of data that you don’t need to fulfill your requirement. If you have a page where you are only displaying the Departments, you are also selecting the Employees for each Department. Let’s imagine that you have a Department entity with an relationship to Employee defined with Eager Fetching. Eager FetchingĮager Fetching is a strategy that allows you to get additional data when you are loading an entity to have everything available for your needs.(but at what cost?) There's also another great post by Thorben Janssen where he talks about JPA features that can help with the application performance: boosting your application performance with JPA. I hope this article could raise some awareness and guide developers to write better and faster JPA code. Shamefully, I always find them out during my analysis after the fact, even though they seem completely obvious! In any case, I believe that these mistakes are not deliberately put into the application-most of the time, it’s poor knowledge about the technology itself. I’ve written down four areas in which I usually find all the issues: these are the ones I check first when I have to hunt down JPA performance problems. I feel that the majority of the developers are only concerned about getting the data they need, and don’t worry about anything else.Īnd this is why I decided to write this article: I’ve seen the same mistakes repeated over and over again, and they actually have a huge performance impact. On the other hand, you also need to have some knowledge of what’s going on behind the scenes or you’ll be in for some unpleasant surprises.īelieve it or not, I met a few developers that had no idea that JPA uses a database underneath. You can write database access code very easily and get most of the general database operations out of the box without having to write all that tedious JDBC code. A bad thing about JPA is that abstracts your interaction with the underlying database. The Pros and Cons of JPAĪ great thing about JPA is that abstracts your interaction with the underlying database. If you have some basic knowledge of JPA (which you should to get the most out of this article), then I can bet that many of you have heard a similar exchange before. “Just deal with it!” exclaims Robert, hanging mutters Dan. “Well Robert, it seems the database is flooded with queries! What the hell is this application doing?” cries Dan. Can’t you create some indexes, or do something to speed it up?” “Hey Dan,” Robert says, “Lea says the application is slow. Let me ask our database admin, Dan,” and he picks up the phone. “Our code is impeccable, so this is probably a database problem. ![]() ![]() “Dude, our application is slow,” she tells Robert. The day is clear and sunny, birds chirping happily as Lea, a project manager, makes her way to a meeting with Robert, a development team lead. Unfortunately, I came to realize that this technology is commonly used improperly, which generates a lot of complaints and even full-scale wars between database administrators (DBAs) and developers. Over the last few years, I’ve come across with several enterprise applications that use JPA to manage their data, which is cool since JPA is a very powerful and awesome specification. Lastly, we give advice on how to avoid those issues in the first place. In this blog, we look at the pros and cons of JPA, how to improve JPA performance, and provide performance improvement stats to help you choose the best method first. But that abstraction can come at a performance cost. JPA is a useful tool for Java development, allowing developers to abstract interactions with the underlying database.
0 Comments
Leave a Reply. |