Red Hat

In Relation To Interview

In Relation To Interview

Meet Anghel Leonard

Posted by    |       |    Tagged as Discussions Hibernate ORM Interview

In this post, I’d like you to meet Anghel Leonard, a software developer, blogger, book author, and Java EE aficionado.

Anghel Leonard, align=

Hi, Leonard. Would you like to introduce yourself and tell us a little bit about your developer experience?

Hi Vlad, thanks for having me. My name is Anghel Leonard (@anghelleonard on Twitter), I’m living in a small village in Romania, and I’ve been a software developer for the last 17 years, mainly focusing on Java and Web development. I’m also a blogger and author of several books.

My career started as a Java developer in the oil field (Petrom S.A.). Mainly there I’ve been part of the team whose goal was to develop applications in the oil simulation field (Java desktop applications meant apply some specific mathematical models). After some time, we switched to web applications (based on HTML, Servlets /JSP and Struts) and we brought databases into the equation as well (especially MySQL and Visual FoxPro). About then I’ve started with Hibernate ORM, "native" API.

Shortly, I’ve started to learn Java EE (mainly, JSF, EJB, and JPA) and Spring. Further, I’ve worked for many years in GIS field developing RIA and SPA web applications. Since then I’m constantly using Hibernate implementation of the Java Persistence API (JPA) specification. By their nature, GIS RIA/SPA applications process a lot of data (spatial and non-spatial data) and must run fast, so I’ve always been interested to optimize the performance of the persistent layer. I can say that I’ve seen Hibernate "growing" and I’ve constantly tried to learn about every new feature and improvement it brought :)

Currently, I’m working as a Java CA. My main task here is to perform code reviews on a significant number of projects of different sizes, technologies, and areas of interest. Many of these projects use Hibernate "native" API and Hibernate JPA.

You are a very prolific writer, having published several books about JSF, Omnifaces, Hibernate, MongoDB and even JBoss Tools. Now that you are self-publishing your latest book, can you tell us the difference between working with a publisher and going on your own?

Well, I think that it is obvious that choosing between a publisher and self-publishing is a trade-off matter. From my experience, there are pros and cons on both sides and I can highlight the following aspects:

Publisher vs self-publishing pros:

  • publishers provide grammar and check spelling (this can be a major advantage for non-native English speakers, as me) and technical reviewers (usually, authors can recommend reviewers as well) while in self-publishing the author must take care of this aspects

  • publishers take care of book’s cover and index while in self-publishing the author must do it

  • publishers can consider the author very good and contact him for further contracts on the same topic while this is not true in self-publishing (at least, I did not hear of it)

  • publishers provide constant and consistent assistance during the writing process (e-mail or Skype) via editors, project coordinator, technical stuff, etc while in self-publishing this is not available

  • for authors is 100% costs free while in self-publishing the costs can seriously vary

  • publishers can be powerful brands on the market

Publisher vs self-publishing cons:

  • publishers can reject a book proposal for different reasons (e.g. they already have too many books on the suggested topic) while in self-publishing the chances to be accepted are significantly bigger

  • publishers work only with deadlines (each chapter has a fixed date and the book has a fixed calendar) while is self-publishing the author decides when to release an updated version and how significant the update will be

  • publishers provide "Errata" for book issues (typos, mistakes, technical leaks, content accuracy issues, etc) and those issues can be fixed only in subsequent versions of the book while in self-publishing the author can fix issues immediately and repeatable

  • publishers usually pay significantly smaller royalties in comparison with self-publishing

  • typically, publishers pay royalties at every 6 months, while in self-publishing is more often

  • publishers are not quite flexible about the book size, aspect, format, writing style, etc while in self-publishing these coordinates are very flexible

  • publishers require to be the only owner of the book content and it is forbidden to publish it in any other place or form while in self-publishing this restriction is not always applied

  • publishers set the price of the book without consulting the author while in self-publishing the author sets the price (moreover, the author can choose the price in a range of values)

  • publishers decide the discounts and donations policy while in self-publishing the author can provide coupons, discounts and make donations.

Your latest book is called "Java Persistence Performance Illustrated Guide". Could you tell us more about this new project of yours?

Sure thing.

Well, in the beginning, the content of this new book was not meant to be part of any book. The story is like this: Over time, I have collected the best online articles about Java persistence layer (JPA, Hibernate, SQL, etc) and, on my desk, I have some of the most amazing books about these topics.

I think there is no surprise for you if I say that your blog and book, High-Performance Java Persistence, are major parts of this collection.

In order to mitigate the performance issues related to persistence layer, I strongly and constantly recommend these resources to developers involved in persistence layer, but the remaining question is: in a regular day of work, how the members of a team can quickly understand/recognize a performance issue in order to fix it?

Well, there is no time to study in that moment, so I decided to have a new approach: have drawn of a specific performance issue and for 5-15 minutes talk on that draw (after all, "a picture is worth a thousand words"). This way, the audience can quickly understand/recognize the issue and have the hints to fix it.

Further, I’ve published these draws on Twitter, where I was surprised to see that even without the words (the talk), they were appreciated. Well, over time I’ve collected a significant number of draws and people started asking me if I will publish them somewhere (I remember that we had a little talk about this on Twitter as well). And, this is how the idea of the book was born. :)

The main reason of choosing the self-publishing approach was the fact that I’m not constrained by fix deadlines. The only extra-effort I’ve done was to find somebody to make the cover - it was designed and drawn by an excellent painter, Mr. Barsan Florian.

Now, the goal of this book is to act as a quick illustrated guide for developers that need to deal with persistence layer performance issues (SQL, JDBC, JPA, Hibernate (most covered) and Hazelcast).

Each drawing is accompanied by a short description of the issue and the solution. It’s like "first-aid", a quick and condensed recipe that can be followed by an extended and comprehensive article with examples and benchmarks, as you have on your blog.

Most of the applications that I reviewed are Java EE and Spring based applications. Since most of the performance penalties have their roots in the persistence layer, I tried to make a top 10 of the most frequent programming mistakes that cause them (this trend was computed from ~300 PRs in different projects and it is in progress):

  1. Having long or useless transactions (e.g. using @Transactional at class level on Spring controllers that delegate tasks to "heavy" services or never interact with the database)

  2. Avoiding PreparedStatement bind parameters and using "+" concatenations for setting parameters in SQL queries.

  3. Fetching too much data from the database instead of using a combinations of DTO, LIMIT/ROWNUM/TOP and JOINs (e.g. in the worst scenario: a read-only query (marked as read-only or not) fetches all entities, a stream is created over the returned collection, and afterwards, the findFirst stream terminal operation is executed in order to fetch and use further a single entity).

  4. Wrong configuration of batching (the team lives with the sensation that batching is working behind the scene, but they don’t check/inspect the actually SQLs and batch size)

  5. Bad usage or missing transaction boundaries (e.g. omitting @Transactional for read-only queries or executing separate transactions for a bunch of SQL statements that must run in a single transaction)

  6. Ignoring the fact that data is loaded eagerly.

  7. Don’t rely on a pool connection or avoid tuning the pool connection (Flexy Pool should be promoted intensively). Even worse, increase the connections number to 300, 400.

  8. Use unidirectional one-to-many associations with insert and delete entities operations

  9. Using CriteriaBuilder for all SQL statements and rely on whatever is generated behind the scene

  10. Lack of knowledge about Hibernate features (e.g. attributes lazy loading, bytecode enhancement, delay DB connection acquisition, suppress sending DISTINCT to the database, etc)

We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

First I want to congratulate the whole Hibernate team because is doing a great job! I really love the latest features and the comprehensive improvements in documentation. Taking into account the type of applications that I’m involved in, I will like to see the Hibernate - CDI integration ready.

Thank you, Leonard, for taking your time. It is a great honor to have you here. To reach Leonard, you can follow him on Twitter.

Meet Kevin Peters

Posted by    |       |    Tagged as Discussions Hibernate ORM Interview

In this post, I’d like you to meet Kevin Peters, a Software Developer from Germany and Hibernate aficionado.

Kevin Peters, align=

Hi, Kevin. Would you like to introduce yourself and tell us a little bit about your developer experience?

My name is Kevin Peters, and I live in Germany where I work as a Software Developer. My first contact with the Java language was around 2005 during my vocational training, and I fell in love with it immediately.

I worked for several companies leveraging Java and Spring to implement ERP extensions, customizing eCommerce systems and PIM solutions. Nearly one year ago, I joined the GBTEC Software + Consulting AG, one of the leading suppliers of business process management (BPM) software, and there we are now reimplementing a BPM system in a cloud-based manner using Dockerized Spring Boot microservices.

You have recently mentioned on Twitter a DataSource proxy solution for validating auto-generated statements. Can you tell us what about this tool and how it works?

We use Spring Data JPA with Hibernate as JPA provider to implement our persistence layer, and we really enjoy the convenience coming along with it. But we also know about the "common" obstacles like Cartesian Products or the N+1 query problem while working with an ORM framework.

In our daily technical discussions and during knowledge transfer sessions we try to raise awareness for these topics among our colleagues, and in my opinion, the best way to achieve this is implementing tests and real world code examples showing that practically.

I started to prepare a small mapping example for one of our technical meetings, called "techtime", to demonstrate the "unordered element collection recreation" issue, and I wanted to show the unexpected amount of queries fired in this simple use case.

Fortunately, I came across the ttddyy/datasource-proxy GitHub project which helped me a lot to make that problem tangible. The datasource-proxy project empowers you to wrap your existing datasource with a proxy and allows you to count all executed queries separated by query type (e.g. INSERT, UPDATE, etc.). With that opportunity you can not only write tests which assert that you are doing the right thing within your use cases, you can also check if you are doing it in an effective way and avoid the traps I did mention before.

At the time when our Coding Architect Ingo Griebsch suggested to use this approach to enhance our test environment by automating the hunt for performance penalties, you caught us talking about your article on Twitter.

Proxies are a great way to add cross-cutting concerns without cluttering business logic. For instance, FlexyPool brings Monitoring and Fallback capabilities to connection pools. Are you using Proxies for other concerns as well, like logging statements?

There are many ways to enrich application code with proxies, facades or aspects. Starting with small things like logging with a facade like SLF4J, using Spring Security for access control, Hystrix service-to-service communication or even "basic" stuff like transactions in Spring Data, all these features are working with proxies, and we won’t miss them anymore.

Why did you choose Hibernate for that particular project, and did it meet your expectations, especially when it comes to application performance?

Hibernate provides a lot of convenience to us, especially if we combine it with Spring Data JPA. But the fact I enjoy most is that you can still switch to Hibernate specific features like Hibernate Named Queries or special Hibernate annotations.

It’s important to know when you can relax using "magic" ORM features and when the opposite is needed - forgo bidirectional relations and write HQL instead or even using database native queries to receive complex data. In our opinion, Hibernate offers the best balance between convenience and performance if one knows how to use it.

Hence, we have a quite complex data model and customers which store a lot of data it’s vital for our software to fetch and write data in a performant way in every of our use cases. And in case of any doubts, at least your articles help us getting things done right.

We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

In general, we love the feature set of Hibernate. Only the support of UNION HQL queries/Criteria API would be an awesome feature that we missed recently.

Thank you, Kevin, for taking your time. It is a great honor to have you here. To reach Kevin, you can follow him on Twitter.

Meet Marco Pivetta

Posted by    |       |    Tagged as Discussions Hibernate ORM Interview

In this post, I’d like you to meet Marco Pivetta, who is one of the maintainer of Doctrine, a suite of PHP projects that were inspired by Hibernate ORM.

Marco Pivetta, align=

Hi, Marco. Would you like to introduce yourself and tell us a little bit about your developer experience?

I’m Marco "Ocramius" Pivetta, an Italian PHP consultant, currently living in Germany. Yes, the nickname is weird, but it comes from an era of Quake 3 Arena, Unreal Tournament & co.

I’ve been tinkering with computers since I was a child, and have been working with PHP for more than half my life now, developing a love-hate relationship with the language. Interestingly, I didn’t start with the usual Joomla/Wordpress/Drupal/etc, but built a quite complex website that interacted with a browser game called "OGame", and scraped game information through a Firefox addon that would then provide an additional information to the players.

The reason why this project ("stogame") is important for me is that it included extremely challenging problems to be solved for a rookie with no help at all, and is still one of the most complex projects that I worked on:

  • XSS/SQL injections - had those, wasn’t fun

  • queuing mechanisms to sync browser extensions and the website - invented my own system

  • optimizing queries and indexes on ~60Gb of MySQL MyISAM tables

  • disaster recoveries on such a system - had those too, wasn’t fun either

  • real-time push mechanisms for clients via BOSHXMPP

  • simplistic prediction engine to aid players in decision making

All of the above were built by 15-years-old-me by just spending countless sleepless nights on it, and also jeopardizing my school evaluations. Still, this was before libraries, design patterns, mentoring, Github: only me, some friends, and a good amount of design and prediction work.

I then moved on, gave up on the project, failed university (I’m a terrible student), got a few jobs and started using frameworks. Eventually, I got to work with all of the typical DB abstraction approaches:

  • Active Record (with ZendFramework)

  • Table Data Gateway - in a custom solution

  • Data Mapper - in a Java EE project

I liked the JPA approach in the Java EE project so much that I started looking for a PHP analogue solution for my daytime job, and ended up discovering Doctrine 2.

Since then, I started getting more and more involved with the project, starting from answering questions on the mailing list and StackOverflow. Benjamin Eberlei, who was the lead on the project at that time, pushed me towards contributing with actual code changes back in 2011.

Eventually, I became part of the maintainers of the project, and that also boosted my career, allowing me to become a consultant for Roave, which allows me to see dozens of different projects, teams and tools every month, as well as a public speaker.

You are one of the developers of Doctrine ORM framework. Can you please tell us what’s the goal of Doctrine?

I am actually not one of the developers, but one of the current maintainers. The initial designers of the current Doctrine 2 ORM, as far as I know, are Jonathan Wage, Guilherme Blanco, Benjamin Eberlei and Roman Borschel. I can probably still answer the question: Doctrine ORM tries to abstract the "database thinking" away from PHP software projects, while still being a leaky abstraction on purpose.

To clarify, most PHP developers are used to developing applications from the database up to the application layer, rather than from the domain logic down, and that’s a quite widespread problem that leads to hardly maintainable and unreadable code. This tool gets rid of most of those problems, by still allowing developers to access the database directly when needed.

Ruby on Rails employs the Active Record pattern. Why did Doctrine choose the ORM paradigm instead?

Interestingly, Doctrine 1.x was an Active Record library, and also a quite good one, but it became evident quite quickly that the JPA specification and Data Mapper plus Unit of Work were better solutions altogether.

Specifically, the Data Mapper approach allows consumers of the library to write abstractions that decouple the tool from the domain almost completely (there are always limitations to this). The Unit of Work pattern has an increased memory impact for PHP applications, but also massively reduces required query operations (via in-memory identity maps) while adding some transactional boundaries, and that is a big win for most PHP apps, which often don’t even use transactions at all.

There are more advantages, but I personally wouldn’t ever consider using Active Record again due to its limitations and inherent framework coupling. This doesn’t mean that Active Record doesn’t work, but I’ve been burnt many more times with AR than with DM.

Since Hibernate ORM has been influencing Doctrine, can you tell use the similarities and differences between these two frameworks?

Doctrine is hugely inspired by Hibernate and the JPA, although we couldn’t really copy things, both due to licensing issues and life-cycle differences in Java and PHP software.

Doctrine resembles Hibernate in the Unit of Work, mappings, basic event system, second level cache and the DQL language (HQL in Hibernate). We even designed an annotation system for PHP, since the language doesn’t support them, and it currently is the de-facto standard for custom annotations in PHP libraries, and we initially only needed this to simulate inline mappings like Hibernate allows them.

Where things differ a lot are flexibility and lifecycle, since Java is an AOT-compiled language with a powerful JIT and generally deployed in long-running applications.

PHP is an interpreted language, and its strength is also its pitfall: the typical share-nothing architecture allows for short-lived, memory-safe, retry-able application runs. That also means that we have no connection pooling, and the ORM internals are much more inflexible and less event-driven than Hibernate’s due to memory and execution time constraints. That also means that we rarely encounter memory issues due to large Unit of Work instances, and connections and entity instances aren’t shared across separate web application page loads, and slow ORM will unlikely slow down an entire application server.

Another huge difference is managed state: DETACHED makes little sense in the PHP world, since a detached entity may only come from serialized state. In Doctrine 3.x, we are planning to remove support for detaching entities, since storing serialized objects in PHP is generally leading to security issues and more trouble.

As you can see, the differences are indeed mostly in the lifecycle, but each language and framework has its strengths and pitfalls.

We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

I’m probably being weird here, but I don’t lack any particular features from either ORM at this time. What would be interesting is reducing support for entity and transaction lifecycle events, since most consumers of these ORMs tend to code application and domain logic in those, while they were mostly intended for technical tasks, such as creating audit logs and executing pre- and post- DB cleanup tasks.

A possible improvement is to explore saving/loading of single aggregate-root-acting entities attached to a Unit of Work, which is only responsible for tracking state in child aggregates. This is only to prevent sharing entity references across aggregates, and to prevent DB transactions from crossing aggregate root boundaries.

Thank you, Marco, for taking your time. It is a great honor to have you here. To reach Marco, you can follow him on Twitter.

Meet Dmitry Alexandrov

Posted by    |       |    Tagged as Discussions Hibernate ORM Interview

In this post, I’d like you to meet Dmitry Alexandrov, who, not only that he’s a well known Java technologist and conference speaker, but he’s also a polyglot, speaking 6 languages (e.g. Russian, Bulgarian, Ukrainian, English, German, and French).

Dmitry Alexandrov, align=
  1. Hi, Dmitry. Would you like to introduce yourself and tell us a little bit about your developer experience?

    Hi! My name is Dmitry Aleksandrov and currently for more than a year I’m a Principal expert developer and architect at T-Systems. I’ve got 10 years experience mainly in Java EE/Spring stack.

    Most of my time I was dealing with big enterprise projects in banking, insurance, and telecoms. Along with four other awesome guys, I’m a co-lead in the Bulgarian Java User Group and jPrime conference co-organizer.

  2. You have recently published an article about a major performance optimization you underwent in one enterprise project. Can you tell us what are the most common performance issues in enterprise systems?

    Surprisingly, or actually not so much surprisingly, the most of the optimizations in enterprise projects are made on the persistence layer. The way the data is stored and accessed is essential as the most of the latency may come out of there.

    The other source of latency may be the remote calls, but the only way gain performance there is to reduce their quantity and upgrade the hardware architecture. As for the persistence much more can be done in this field. It is essential to really pay attention to what is taken out the DB and what is shown to the user. Heavy CPU processing is rarely seen, at least from my experience.

    So. it is really important to invest time in a good design of the persistence layer. ORMs are doing really great job, and the automation they have brought saves tremendous efforts, time and money. But at the same time, the users of the ORMs are a little bit spoiled of the magic they bring.

    The developers and architects tend to design the object model as the primary source of data and the DB schemas as a product of the model and heavily rely on the ORM to manage this. This quite often leads to very suboptimal data representation in the RDBMS thus performance issues, since the mathematics in Relational Databases are much different from those of the programming language objects. And those mistakes are often very hard and expensive to fix, as DB schemas are extremely hard to change especially when they are in production already.

    And the ORM, although it is an extremely smart tool nowadays, is still not an AI (yet). So to deal with those problems, I believe that every enterprise or full stack developer should invest more time in educating in Databases and the way their programming language interacts with them. A good persistence layer design may solve the most of the performance issues or even fully prevent them from happening.

  3. Hibernate offers many optimizations that aim to increase application performance. Has Hibernate met your goals in the projects you’ve been involved with?

    Yes, definitely. Although we try to use as much standard JPA as possible, on our final customer deployments we also do Hibernate specific optimizations, like pre-build code instrumentation if we use Hibernate version 5. In one of my previous project we have used some second-level caching, and Hibernate integrated almost seamlessly.

  4. You are a Java EE aficionado and international speaker. How to you see the future of Java EE and JPA in the context of cloud computing and Microservices architectures?

    Java EE is a subject of many discussions recently. Quite a lot of even fatal prognoses were made, but I personally believe Java EE will still be there and make big progress. There is a huge аmount of companies and enterprises that build their business with Java EE technologies, and they won’t disappear soon since EE is a proven standard.

    Actually, this is the main advantage of Java EE – it is a standard. It means it is guaranteed, a reliable and tested set of functionalities that have the same behavior and results on all supported platforms. And a standard is not something that is just assigned, standards are established based on what’s the best and most valuable in current technology at the moment. And the establishment of these technologies the most often comes from the community.

    A good example of community effort is exactly the Microprofile initiative, which is driven by Independent Java EE Server vendors. As Microservices are now very popular, the activists try to create a really common solution for the best utilization of this architecture on Java EE.

    Although there are some controversies about what should this profile include, there is a starting point. The discussion is open, and everybody is welcome to contribute. Actually, it is very curious to see how a standard is being born! The guys are doing a great job! Another example is the Java EE Guardians who are doing great input in all aspects of the Java EE evolution!

    As for the cloud, Oracle has made some promises that they will put more efforts in a better Java EE cloud integration. But as for now in our environments, we have a mixture of PaaS and IaaS solutions. Like some of the servers are Dockerized or packed as executable jars and running somewhere in the cloud, and the databases are provided like services. But there we have some issues with the latency.

  5. We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

    I am now waiting for the full support of the Entity Graph functionality. I personally believe that’s a very handy way to have a good fine control over what you fetch and can give some really good performance improvements, especially on systems which are in production already.

Thank you, Dmitry, for taking your time. It is a great honor to have you here. To reach Dmitry, you can follow him on Twitter.

In this post, I’d like you to meet Simon Martinelli, who, among many other things, is teaching Java EE and JPA at the University of Applied Sciences in Berne.

Simon Martinelli, align=
  1. Hi, Simon. Would you like to introduce yourself and tell us a little bit about your developer experience?

    I’m a software architect, developer, and trainer from Switzerland working for simas GmbH. Besides that, I’m a lecturer for Java EE, architecture and design and persistence technologies at the University of Applied Sciences in Berne. In my spare time, I’m working on some open source projects and as I’m an expert group member of JSR 352 Batch and JSR 354 Money and Currency API.

    I started my IT career in 1995 as a Cobol developer on IBM mainframe. Since 2000, I’ve been working in many enterprise projects as a developer, architect, and technical lead, using J2EE/Java EE, Spring framework, and from time to time .NET. My first contact with OR-Mapping was in 2000 when we used TopLink in a project for Swiss Railways.

  2. You have an open-source project on GitHub called Query Language Result Mapper. Can you tell us what’s the goal of this framework?

    I love the JPA constructor expression. In my opinion, it’s the best way to get around the common performance problems when using JPA in a naive way. But the constructor expression only works with JPQL or Criteria API and sometimes you need to execute a SQL query but don’t want to use a fully featured SQL framework like jOOQ.

    Sure, JPA comes with the ConstructorResult but I find it too complicated, and it was not available with JPA 1.0. Hibernate has the ResultTransformer, but this only works with Hibernate. So I decided to start Query Language Result Mapper (QLRM).

    QLRM simply tries to find a matching constructor based on a JPA native query result or, when using plain JDBC, a JDBC ResultSet. It’s simple, small and not related to a specific JPA implementation.

  3. You are also teaching Java EE and Java Persistence API at the University of Applied Science in Berne. Is JPA easy to learn? What do your students think of this Java Persistence standard?

    JPA is by far the most complicated part of Java EE to learn. Because it’s leaky abstraction, you have to know a lot about SQL databases and what’s going on behind the scenes. It’s also the most common source of performance problems. While teaching, I always try to focus on how to avoid these performance problems.

    My students usually like JPA because it makes data access much easier. For those who don’t know the history of OR-Mapping, it’s hard to understand that the JPA implementation behaves differently in some situations. What they don’t like is that (currently) JPA does not support the Java 8 Date Time API.

  4. Since I started blogging, I realized that explaining a subject helps me better understand it. Do you think all developers should be involved in teaching or writing articles or books about the subjects they want to master?

    Absolutely! I’m teaching JPA since 2007, and this forces me to get a deep understanding of the topic because the questions of the students can be very challenging. Sometimes I even have to look at the code of the JPA implementation to understand what happens under the hood. In return, this know-how helps me to write better and faster applications.

    As Albert Einstein said: "If you can’t explain it simply, you don’t understand it well enough."

  5. We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

    I think the whole Hibernate team is doing a great job! It’s more than feature-complete (it’s hard to know every feature, though).

    Just one minor thing: When reading the documentation it’s often hard to differentiate what’s JPA standard and what’s Hibernate specific. But I don’t think that this is very important because not many developers are switching the JPA implementation in a project.

Thank you, Simon, for taking your time. It is a great honor to have you here. To reach Simon, you can follow him on Twitter.

In this post, I’d like you to meet Christian Beikov, who is one of the most active Hibernate contributors.

Christian Beikov, align=
  1. Hi, Christian. Would you like to introduce yourself and tell us a little bit about your developer experience?

    Hey, Vlad. My name is Christian Beikov, and I am 25. I’m living with my girlfriend in Vienna, the capital city of Austria. I started working with Java EE technologies in school and continued to do so at my first job where I am still employed part-time. Next to my job, I am doing my master studies in Software Engineering at TU Wien which I am hopefully finishing next year.

    My main interests are in distributed systems, database technologies and everything Java/JVM-related. In school, I came into contact with Java EE for the first time when I was by developing a JSF-based web app with Hibernate on top of GlassFish with NetBeans. When I started my job at Curecomp GmbH, I mainly worked with Eclipse and WebSphere and about 2 years ago, I managed to fully migrate the company’s development stack to WildFly and IntelliJ IDEA. During these migrations and the countless university assignment projects in which I have used Hibernate, I’ve stumbled upon one or another bug.

  2. You’ve been very active in the Hibernate ecosystem, sending Pull Requests and getting involved in future design discussions. How do you manage to blend the open-source involvement with your day job?

    The work I am doing in open-source projects happens mostly in my free time. I like to give back something to the community, even if it’s just bug reports. Since I use Hibernate in so many projects, I also see my contributions as an investment in improving the overall quality of the projects I do.

    At my day job, I am sometimes facing problems that I simply can’t workaround or doing a proper fix seems equally hard to me, which is how I justify fixing the Hibernate bug in the core. The deep knowledge that I gain from analyzing bugs and discussing features also helps me in my day job when reasoning about the behavior of Hibernate in certain situations which is a big plus.

  3. You are also developing Blaze Persistence. Can you tell us a little bit about this framework and how does it compare to Criteria API?

    Blaze-Persistence is a library on top of the JPA APIs. The core module provides a fluent query builder API that allows you to express queries in a Java DSL which should feel mostly intuitive. In addition to the standard features that are defined in JPA 2.1, it also implements support for some common functionality that already every JPA provider supports like for example aliasing fetch joins or entity joins. On top of that, Blaze-Persistence also provides deep integration with the JPA provider to support features like (recursive) CTEs or set operations like UNION, etc. Beware that the deep integration is currently only available for Hibernate since it is the provider I am mostly familiar with, but support for others is planned.

    One of the greatest features that Blaze-Persistence makes possible are Entity Views which are to JPA entities roughly what views are to tables in the RDBMS sense. An Entity View is an interface or abstract class that represents the structure of a projection for an entity. It’s basically the definition of a DTO, with the difference that you only need to specify getter methods along with the projection for that attribute as JPQL expression. When you then apply the Entity View on a base query, it will contribute the JPQL expressions as select items, thus creating an optimized JPQL and SQL query. The result of such a query, of course, is a list of objects that are a subtype of the Entity View. Apart from avoiding all the manual plumbing code to get the data into shape, you can make use of features like Collection mappings, Subviews or SubqueryProviders which let you define complex projections that one would normally not do.

    The Criteria API provided by JPA is hard to use as it requires a lot of typing and also some kind of skill. You need to know how to wire things up which is one of the big pain points that I tried to solve by introducing a fluent API. Sure the JPA Criteria API is type-safe, but that comes at the cost of obfuscating your query. A type-safe variant of the Blaze-Persistence core API or maybe even just some additional methods in the existing API are already on my roadmap, so I will also try to fill this gap while retaining readability.

    Since I don’t expect everyone to rewrite his existing JPA Criteria API based queries, I also implemented the JPA Criteria API on top of the Blaze-Persistence core API. You can even let your existing code build the queries with the JPA Criteria API and retrieve a Blaze-Persistence query builder from it. The resulting query builder can be used just like any other query builder which means you can use CTEs and all the other great features.

  4. Blaze Persistence works with any JPA provider. From your experience, how does Hibernate ORM compare to EclipseLink or OpenJPA?

    Just as a disclaimer, I haven’t dug too much into the communities of the other JPA providers as I don’t use them in any of my projects. Also, beware that I might be biased now since I know people from the Hibernate team and know who to contact if I have a problem, but I’ll try to be as neutral as possible.

    I got the feeling that the EclipseLink community didn’t care about the bugs I reported or forum posts I did, but apart from that, the implementation seems ok. It has some quirks like e.g. allowing lazy loading although the underlying entity manager is closed, but maybe that’s a feature :D

    DataNucleus which is one of the lesser known JPA providers is actually pretty good and the main developer there reacts super fast to bug reports. I found some bugs and also proposed some features to increase Hibernate compatibility and as far as I know, all of these issues have been resolved by now.

    I can’t tell you much about OpenJPA except that it seems rather dead or in maintenance mode only to me. The latest version is only JPA 2.0 compatible and unfortunately, lacks even proprietary ways to do certain things that are possible with other JPA providers.

    The thing I am mostly unsatisfied with is that most of the issues I found with any JPA provider are pretty basic things and should be asserted by the JPA TCK. I hope some Oracle guy who can actually do something reads this and pushes harder to make the JPA TCK open-source :)

  5. We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

    I think Hibernate already does a very good job. What I really would like to see is the decoupling of the SQL generation and execution from the ORM specifics. This is something I often would have needed in one way or another to workaround bugs or simply to execute the SQL that is needed for a specific task. Imagine you could specify a HQL query that just describes how the result mapping should be done, but specify your own SQL. This is something I am doing internally in Blaze-Persistence all the time for advanced queries. I hope the SQM feature that is planned for Hibernate 6 will allow me to do that so I can get rid of the dirty tricks I have to do right now to get stuff done.

Thank you, Christian, for taking your time. It is a great honor to have you here. To reach Christian, you can follow him on Twitter.

In this post, I’d like you to meet Rafael Winterhalter, Java Champion, JavaZone conference organizer, and Team Leader of Byte Buddy.

Rafael has done a great job migrating Hibernate from Javassist to Byte Buddy, for which we are very grateful.

Rafael Winterhalter, align=
  1. Hi, Rafael. Would you like to introduce yourself and tell us a little bit about your developer experience?

    Hei, I am Rafael, a native German who is living in Oslo, Norway where I work as a software consultant.

    Before that, I was in academia where I did a fair share of statistical analysis what evoked an interest in computer performance. After I left university, I have been working mostly with the JVM where I still enjoy working with performance critical systems but where I also do a lot of enterprise software development.

    I am also quite active in open source and as a conference speaker and organizer.

  2. You are the Team Leader of the Byte Buddy open-source framework. Can you tell what’s the goal of Byte Buddy?

    Byte Buddy originated out of frustration over cglib, a commonly used library for code generation that got abandoned a few years back. I was working on a proxy component that needed to retain the annotations of the proxied methods.

    Proxies are often implemented as subclasses where these annotations disappear as method annotations are never inherited. Many libraries such as Hibernate do however use annotations as part of their API what breaks this pattern. I got stuck and wrote a tiny library as a replacement for cglib which later evolved into what is Byte Buddy today.

    Today, the library‘s goal is to be the fastest and easiest way to define or modify Java classes at runtime. As a side goal, I wanted to offer some support for Android which was previously lacking a runtime code generation library and I wanted to make it easy to define Java agents.

  3. In 2013, you wrote the cglib: The missing manual article. How does Byte Buddy compare to cglib or javassist?

    I wrote this article as a heavy user of code generation libraries in open source and to share a bit of my knowledge of cglib which is not supplemented by any documentation. I still believe that this is one major issue of code generation libraries; due to the lack of documentation, many people fear using them for not understanding how they work despite their usefulness.

    Other than Byte Buddy, cglib is limited to creating subclasses of existing types where it can override existing methods. Byte Buddy gives you full freedom in defining additional fields or methods and allows you to implement methods arbitrarily. In practice, this often results in thinner byte code and better performance.

    Also, Byte Buddy does not require you to include any library-specific classes into the generated code what is crucial for OSGi-environments. Also, this will become a necessity when working with Java 9 modules which the authors of cglib did of course not anticipate 15 years back.

    Javassist has a proxy API that is similar to cglib which does, however, come with the identical limitations. Additionally, Javassist allows for arbitrary modifications of classes using a different API by supplying Java code as strings. While this approach gives you full freedom, it is very vulnerable to API-changes which then yield runtime errors and also opens up to code-injection when processing user input, similar to SQL-injection when using JDBC.

    Byte Buddy rather works with precompiled code which can be written in any JVM language and which can be inlined at runtime. Avoiding runtime compilation makes Byte Buddy’s transformations type-safe and much faster to apply at runtime.

  4. You have contributed to many open-source projects, Byte Buddy, Mockito, and now Hibernate ORM. Can you tell us more about the Hibernate and Byte Buddy integration?

    The usage of Byte Buddy in Hibernate ORM and Mockito differs a lot.

    Hibernate mostly uses code generation to implement runtime proxies. For the Hibernate enhancer, it does, however, require some rather fundamental changes of a code base by installing its own callbacks into classes in order to better monitor an object’s state. Fortunately, all such enhancement is done in a dedicated step what makes the code manipulation quite predictable.

    In Mockito, we traditionally only required simple subclass proxies. In Mockito 2, we added, however, a new mock maker that inlines the mocking logic at runtime. This way, it becomes possible to mock final classes and methods what is important in order to support new JVM languages such as Kotlin where, by default, all methods are final. With this new mock maker, Byte Buddy needs to rewrite large fractions of a class.

  5. We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

    Hibernate has been my first choice for an O/R Mapper in many years, and I am very happy how well it works. One critique I had was the lack of documentation.

    People are often abusing the library’s capabilities or run into performance issues because they do not understand what the library is doing and what its intended use case is. And to be fair, this is not always easy to figure out.

    I feel like the state of documentation has improved a lot in the last time, and I very much welcome this effort.

Thank you, Rafael, for taking your time. It is a great honor to have you here. To reach Rafael, you can follow him on Twitter.

Meet Julien Dubois and JHipster

Posted by    |       |    Tagged as Discussions Hibernate ORM Interview

In this post, I’d like you to meet Julien Dubois, the Team Leader of JHipster.

Julien Dubois, align=
  1. Hi, Julien. Would you like to introduce yourself and tell us a little bit about your developer experience?

    Hi Vlad, I’m Julien Dubois, and I’ve been a software developer for the last 20 years, mainly focusing on Java and Web development.

    I’m involved in the Open Source and Java communities: I’ve written a book on the Spring Framework, contributed to many different OSS projects, and talked at a lot of conferences.

    Currently, I’m Chief Innovation Officer at Ippon Technologies, a Java consultancy with offices in France, the US and Australia. I’m also the CTO of DataMC, a VC-backed startup specialized in Big Data solutions.

  2. You are the team leader of JHipster. Can you tell us about the goals of this open-source framework?

    It’s all about having a great developer experience: we integrate a lot of cool technologies like Spring Boot, Hibernate, AngularJS and Docker, and automate all the tasks you would usually do manually. In the end, you win a lot of time, and your project has a much higher quality.

    We, of course, have great Hibernate support, and even have an online IDE to help generate complex data models.

    Another great thing is that we have a huge community, with lots of people and companies contributing. This ensures we have tons of ideas, patches and best practices, which is something nobody could ever achieve alone.

  3. JHipster uses Hibernate ORM for data. Why did you choose Hibernate over other JPA providers?

    At Ippon Technologies, I have seen many projects, probably more than 50 in the last 5 years. I’d say 80% of people use JPA and Hibernate together, and the rest have either some custom JDBC code, a proprietary framework (like Jalo, which comes with Hybris), or an Open Source alternative (like MyBatis).

    But I haven’t seen anyone using another JPA provider for a very long time. A couple of years ago, I saw one project which wanted to test Batoo JPA, but that implementation is not maintained anymore.

    So, for JHipster, we use Hibernate because it’s the most widely-used, better-maintained implementation, and also because I trust Red Hat to be a great sponsor for the project.

  4. We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

    My main issue with Hibernate on JHipster is the startup time. On my laptop, I need 10 seconds to start a Hibernate application, compared to 7 seconds for a MongoDB application. All this time isn’t caused by Hibernate itself, as there are also the connection pool and the 2nd-level cache to start, but the whole stack is a bit heavy when coding.

    In production mode, we also need something that starts up really fast, and that’s definitely the biggest issue for me. For instance, when using microservices with Docker, or when using cloud providers like Heroku or Cloud Foundry, this really goes against Disposability (the number 9 of the 12 factors).

    So I’m wondering if we could have an option where Hibernate starts quickly without doing any check, and then fails fast on any error, like an incorrectly-written query.

Thank you, Julien, for taking your time. It is a great honor to have you here. To reach Julien, you can follow him on Twitter.

Meet Thorben Janssen

Posted by    |       |    Tagged as Discussions Hibernate ORM Interview

In this post, I’d like you to meet Thorben Janssen, a long-time Hibernate user and blogger.

Thorben Janssen, align=
  1. Hi, Thorben. Would you like to introduce yourself and tell us a little bit about your developer experience?

    Hi and thanks for having me.

    My name is Thorben Janssen. I’m 36, married and father of a small son. I’m also a trainer, blogger, and developer with a strong focus on JPA and Hibernate and a CDI 2.0 expert group member.

    My career started more than 15 years ago with an internship and the development of various small PHP applications for mobile phone operators. It didn’t take long until I joined the rest of the development team and started to work with EJB 2 and JBoss application servers. In the beginning, that was a painful experience. EJB 2 was hard to learn and created a dislike for XML files that still exists.

    But it also got me into Java EE and the implementation and design of large systems. And that’s what I’ve been doing ever since. During these years, I also managed small to mid-sized development teams and acted as an architect. But I always was and still am a Java EE developer at heart who’s spending as much time as possible in the IDE. I think that the interest for new things and the tools he/she is using is one of the key characteristics of a good developer. I always read about upcoming specification changes or new, proprietary features in their implementations and try them in small side-projects. At some point, I started to share my knowledge with my co-workers, and it led me to my new passion: teaching others by writing and speaking about JPA and Hibernate.

  2. Your site, Thoughts on Java, features a great deal of JPA and Hibernate tutorials. Why did you decide to write about this topic?

    That happened more or less by accident. As I said earlier, I’ve always worked on backend applications, and the persistence tier is an important part of these.

    I’ve always been interested in ways to make the database access easier and more efficient. Simple read and write operations should be easy to implement. Our customers don’t pay us to read some records from the database. They expect us to solve complex business requirements.

    I spend a huge part of my career learning about and even more time implementing efficient database access with Hibernate. When I started my blog, I was looking into the changes introduced in JPA 2.1. I found a bunch of useful, new features, like @NamedEntityGraph, stored procedure calls, and AttributeConverter. I wanted to document them so that I could easily use them in future projects.

    As soon as I shared links to my posts on social media, I was surprised how many developers shared my interest in these things. Hibernate and JPA were my main interest and became the main topics of my blog. That was 3 years ago, and the blog has now grown to more than 100.000 page views per month, a free member library with ebooks and cheat sheets and a small YouTube channel.

    It also provided me the opportunity to speak at conferences and offer classroom and online trainings.

  3. Currently, you decided to run your own training business. Could you please tell us more about it and how it’s been going so far?

    At some point, this was the next logical step. I started with a small side-business and gave a few classroom workshops. At the beginning of this year, I did my first Hibernate Performance Tuning Online Training. There was a lot of interest and it quickly grew to a point where I wasn’t able to work my day job, write the blog and offer training. My wife and I then decided that I should quit my day job and concentrate on my own business.

    So far, that was a great decision. The last 2 months were hard but I also had a lot of fun. The additional time allowed me to finally launch the free member library (a project I wanted to work on since the end of 2015) and a new Hibernate Training.

    In my new Advanced Hibernate Online Training, I explain a lot of advanced JPA and Hibernate features that you can use to create dynamic, type-safe queries, support custom data types, implement multi-tenant applications and manage concurrency. I’m also offering the Hibernate Performance Tuning Online Training in which I show you how to find and fix performance issues. It’s the online version of my 2-day classroom training, and we dive deep into various JPA and Hibernate features that allow you to fulfill high-performance requirements easily. You can have a look at some lectures in this free video series.

    I’m offering both trainings 2-3 times a year with a self-study and a group coaching option. The self-study option provides you lifelong access to the training videos so that you can study at your leisure. The group coaching offers several benefits on top of that, like access to the community forum to discuss your questions and additional exercises. This makes it similar to a classroom training and more effective than the typical online course.

    The registration for both trainings is currently open, and you can join until November 11th.

  4. What are your plans for the future? Will you continue to write about Hibernate or do you also want to write about other topics?

    There are a lot of other interesting Java EE-related topics. But for now, I will focus on JPA and Hibernate. I still have a long list of interesting features I want to write about and I just started to publish Hibernate-related videos on my youtube channel.

    The next big projects will be a 3rd Hibernate training and a book. The 2 existing trainings are for experienced Hibernate users who want to deepen their knowledge and learn to use it more efficiently. The 3rd training will be for Hibernate beginners who want to learn how to map a database table to an entity and how to perform simple queries. I want to work on that in the first half of 2017.

    And the book will be a collection of existing and new Hibernate Tips. That is a popular series on my blog in which I publish a short tip each week, like how to define a query timeout or select scalar values with the Critera API. I will most likely publish it at the beginning of 2017.

  5. We always value feedback from our users, so can you tell us what you’d like us to improve the Hibernate projects (ORM, Search , Validator, OGM) or are there features that we should add support for?

    I like the new Java 8 support you introduced with Hibernate 5. From my point of view, the support of the Date and Time API is a must for modern persistence frameworks and features like repeatable annotations and the support for Streams and Optional make it much more comfortable to use.

    The 2 features I’m missing right now are better support for subselects and discriminator-based multi-tenancy. JPA and Hibernate provide only basic support for subselects. It would be great, if you could use them in the SELECT and FROM clause and not only in the WHERE clause. The discriminator-based multi-tenancy support seems to be already on your list, and I’m looking forward to it.

Thank you, Thorben, for taking your time. It is a great honor to have you here. To reach Thorben, you can follow him on Twitter.

In this post, I’d like you to meet Michael Simons, a long-time Spring and Hibernate user, and NetBeans Dream Team member.

Michael Simons, align=
  1. Hi, Michael. Would you like to introduce yourself and tell us a little bit about your developer experience?

    My name is Michael Simons, @rotnroll666 on Twitter.

    I am a 37 year old developer living in Aachen, Germany. As such, I qualify at least age wise as a senior developer. I’ve been in the software industry for nearly 15 years now. I do have a technical apprenticeship and half finished degree in applied Mathematics. I never finished those studies as I landed in the company I still work with, ENERKO INFORMATIK.

    Apart from being a husband and a father of two, I run our local JUG, the Euregio JUG.

    I’m also a member of the NetBeans Dream Team.

    We, at ENERKO INFORMATIK, create software in the energy and utility markets and work both in the technical and geographical parts as well as sales.

    I did really database-centric software for at least 4 years and, I am still fluent in SQL and also PL/SQL. We once did XML processing inside Oracle databases, which works surprisingly well. After the slow death of Oracle Forms Client / Server, we migrated our desktop applications from 2004 onwards to Java Swing.

    Around that time I played around with Hibernate for the first time. It seemed like the golden bullet back then to get table rows into objects. It wasn’t. But that I learned much later. As Gavin King said: „Just because you’re using Hibernate, doesn’t mean you have to use it for everything.“

    Apart from „boring“ business application, I’ve been not only blogging for a long time but ran several online communities, one of them still alive. Daily Fratze is a daily photo project started in 2005 as a PHP application. Then, in 2006 became a Ruby on Rails site and by 2010, I started migrating it to a Spring and Hibernate backend.

    Looking back at that code I notice how much I didn’t know about the purpose and intention of JPA / Hibernate. As it is true for a lot of stuff, you have to know your tools and the stuff they are designed for. Not all relations are meant to be materialized in objects, not all queries can be generated. And knowledge about when a Session is flushed and when not is essential. It’s not enough to know SQL to fully utilize Hibernate, but it’s also not enough to know Hibernate for abstracting persistence away. I changed the flaws in the site code, but you as the reader of this interview must not learn it the hard way, I really recommend Vlad Mihalcea's book High-Performance Java Persistence.

    My biking project and the site and API of the Euregio JUG are my latest public projects that represent the stuff learned with the experience above. I use those projects as reference projects for my work.

    Since several years, I mostly use NetBeans exclusively for all kind of software development. It supports me for plain Java, Spring, insanely well for JPA entities (build in checks for queries, coding style), for front-end (HTML as well as JavaScript). Most important, it has great integration for code quality related tools like JaCoCo, Sonar and more.

  2. You’ve designed the Java User Group Euregio Maas-Rhine site. Can you tell us what frameworks have you used?

    For Euregio JUG (source is on GitHub), I chose the following:

    • Spring Boot as the application container and glue for

      • Spring Framework and MVC

      • JPA and its implementation Hibernate

      • Spring Data JPA

    • The frontend is done pretty old school by server side rendered templates using Thymeleaf.

      As a rule of the thumb I’d choose the following stack when using any kind of SQL data store:

    • automatic database migrations using Flyway or Liquibase

    • JPA / Hibernate together with Spring Data JPA as long as I can express my domain model as entities and tables

    • JPQL queries if necessary with the benefit that they are checked at application start

    • No native queries hidden away in some annotations

    • If I have to do native queries, I’ll choose Springs JDBC template or since 2015 jOOQ if applicable.

    • My rule for switching to native queries is when I do have projections or „hard“ analytics that would take an awful lot of Java Code instead of a few lines SQL.

  3. Why did you choose Hibernate ORM and Search over other frameworks and did it match your expectations?

    From my background, the data model has always been essential. I worked with awesome models and not so great ones. If you can map your domain to a data model, having a working domain driven design, Hibernate helps you a lot to materialize it back into Java.

    We want to publish articles (posts) and events on the site. People should be able to register for those events, one time each. This fits perfectly into a simple and well understandable domain model that maps perfectly to objects and entities.

    Why bother writing those plain SQL statements for selecting and updating stuff myself?

    I chose the combination of Hibernate and Spring Data JPA for a reason: The domain I map in Hibernate facilitates all the „magic“ Spring Data JPA does: Generating queries, conditions and such: I hardly have to write anything myself.

    If you chose JPA / Hibernate ORM in your project, I really recommend adding Spring Data JPA to the mix. Even if it’s a Java EE project. Spring Data JPA is a bit harder to configure there but provides the user with a lot of helpful stuff.

    Using Hibernate Search integration was an experiment. I’m using it for a long time now on my daily photo project. With little effort, my entities provide access to a Lucene based index and I don’t have to fight with SOLR.

    The EuregJUG site has no local storage in contrast to my daily photo project. So, I had to test drive the upcoming Elastic Search integration in 5.6.0, which works with the same set of annotations, the same entities but not against a local index but against a remote Elastic search index. You can see it in those commits described here and use it here.

    It really isn’t much stuff added, it fits into the repository / DDD approach and matches my expectations.

    Regarding Spring Boot, I’ve been doing Spring now for more than 7 years and Boot since early 2014. It has an awesome community and actually never disappointed me.

  4. We always value feedback from our users, so can you tell us what you’d like us to improve or are there features that we should add support for?

    As a Hibernate user the most common problems I had during the time which I didn’t know exactly what I was doing: Having problems mapping my tables, slow queries and such. Also throwing Hibernate at problems that would have been a better fit for plain SQL caused problems. In both cases, those problems could be solved on my end.

    The experience in Hibernates bug tracker is improving a lot lately and I would appreciate an even better integration with Spring Data JPA.

    To close this, I have to say that I really like the stack mentioned above. We have reached a quality of component where you can really work well from a Domain Driven Design perspective, switch to SQL if needed and still having a clean architecture with clean, testable code. Problems that have been around 10 years ago most often gone.

    It’s really not hard to get an application up and running, including unit and integration tests. If you leave aside the hypes, you can concentrate on both actual problems and on enabling people to learn and do their jobs.

    I really like the fact that Hibernate Spatial find its way into ORM itself. If you have correctly mapped entities and you need to query them via spatial regions, that stuff is really helpful and works quite well. I’d appreciate more information there.

Thank you, Michael, for taking your time. It is a great honor to have you here. To reach Michael, you can follow him on Twitter.

back to top