Although I am fairly experienced in applying JPA to a a web application, I am now facing a challenge in applying it to a desktop application. I could use some pointers!
I working on a JavaFX-based solution, and I'm facing an issue with lazy loading of entity relations. The user interface that I'm after is fairly simple. On one side, there's a listing of entities. Clicking on one of them in the list causes the entity details to be shown on the other side of the screen.
All information needed to display the list is obtained through non-lazy loaded properties of the JPA entities. However, to display the details (after a click), quite a few associated entities need to be retrieved. Given the amount of data, it is not feasible to load all data (eagerly) in memory beforehand, so I'd like the associated entities to be lazy loaded.
Here is where I run into issues with JPA session management. I have not been able to come up with a structured way of having a session active that can be used to lazy load the relations.
In a web-based environment, the session scope is often fairly easy to define. Typically the HTTP request itself can be used to define the lifecycle of a session. The HTTP request forms a very clear start and end point of user interaction. How do you do this in a non-web application?