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.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Viritin MTable with lazy hibernate JPA loading
Hi,
I follow the CDI example at https://github.com/peterl1084/cdiexample.
My datasource is a database, which is accessed via JPA/Hibernate.
I have the following case:
Class A {
/* JPA entity class */
Set<B> manyinstances = ...
}
The instances of Class A are shown in a MTable (so that they can be selected and edited in an AbstractForm).
However, I am not interested in the "manyinstances" property.
Therefore, I want to use lazy loading (in JPA/Hibernate terms) on that property.
However, my impression is that JTable accesses the "manyinstances" property somehow, dispite that it is loaded lazy in JPA/Hibernate
I get the following exception:
com.vaadin.ui.Table$CacheUpdateException
caused by
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role:
Is there a way to load the "manyinstances" property lazy while using MTable (and AbstractForm)?
Thanks.
JG
Hi,
Instantiate MTable so that it only lists the desired properties, not those that would need a lazy loaded relations. An example:
https://github.com/mstahv/jpa-addressbook/blob/master/src/main/java/org/example/MainView.java#L40
If you (in some other case) want to list this manyinstances field in any kind of listing, I suggest to use a join query instead of "lazy loading" as it will be much better performing (1 query vs. 1+n).
cheers,
matti