Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Best practices for developing JPA based master-details tables

Svetozar Radojcin
7 years ago Mar 16, 2016 11:52am
Matti Tahvonen
7 years ago Mar 17, 2016 8:37am


You have a rather large "question". If you could share a small app stub I could probably suggest something more concrete, but here are couple hints that might help you to get forward.

First of, I'd not be afraid of fetching a fresh set of entities from the backend (to e.g. Table or Select components). That is a really easy method to ensure you have valid and fresh data for your UI and it shouldn't be slow. Maintaining an up-to-date datamodel in memory, might indeed be a bit better performing option, but it requires lots of careful programming, especially in clustered environment. Listing data from DB might be/become slow if you use eager fetch type or some other inefficient DB queries.

That's why you most often shouldn't use FetchType.EAGER, if you are aiming for good DB scalability. If you need the related entities in your Table or Grid listings, it is much more efficient to fetch them with a join clause (TIP: try using entity graphs if you are using JPA 2.1). In many cases you don't need the relations in your Table/Grid, at least not all of them. Then, when you select an entity for editing, you should fetch a fully loaded version of it that your pass for your form UI. Even with JPA, there is still a database behind the scenes, and some things just need to be done in the way RDBMSs have been designed to be used. 

Also check our recent

we had in the autumn. It might give you some good tips for your application.


Svetozar Radojcin
7 years ago Mar 17, 2016 3:51pm
Matti Tahvonen
7 years ago Mar 17, 2016 4:03pm
Svetozar Radojcin
7 years ago Mar 20, 2016 10:45am
Matti Tahvonen
7 years ago Mar 20, 2016 7:32pm