I’m trying to mock up a quick proof of concept in Vaadin 10, and running into a brick wall that I’d rather not tunnel through…
I have a Hibernate-backed Spring Data JPA model that is, shall we say, legacy. Due to the way it was constructed, and grown over the years, it has many circular references. For example, a Person may have a collection of Groups he/she belongs to, and in turn each group has a collection of Person objects that are members of the group. Of course, the Groups collection from the Person object is fetched lazily.
I’m binding the Person object to a grid, and have it iterate the groups the person is a member of on the client side. (Kinda like how the bakery app enumerates the order items.)
Generally speaking, if you simply try to iterate through the Person bean and convert it to JSON you’ll hit a stack overflow due to the circular reference. So we annotate many of our collections with the Jackson @JsonIgnore annotation so they won’t get iterated. (In our REST/JSON APIs we have separate methods to retrieve those collections.)
That said, I hit 2 big problems with Vaadin 10. First, using binder.setItems() to bind to the Person object results in a LazyInitializationException as apparently the actual binding happens outside the flow of that call, so the JPA transaction is closed by the time that happens, giving the exception.
The second, the JSON parser doesn’t honor @JsonIgnore (I know It’s a Jackson tag, I didn’t see any other Vaadin-equivalents), and I’m forced to fully initialize or eagerly fetch all the collections, which is a massive performance hit. (Nevermind the circular reference and stack overflow that would arise.) I also don’t see any other way to readily substitute the JSON parser in Vaadin for something more malleable.
Short of either making “fake” objects of the same type with null collections, or creating entirely new beans just for the UI, I don’t see a simple solution. Any ideas?