I\'m developping a mono user desktop application using SWING. I had a little experience with this kind of application on which i used the java.sql api and figured out that i
As I understand, the question boils down to whether you should open EntityManager and store its reference globally and access the same instance everywhere in the application.
I think that should be okay if your application is small to medium size. Just be cautious that database connection (hence session/entityManager) may drop due to various factors. And don't do this with transactions (ie dont open them in beginning and commit in end). Keep transactions as fine grained as possible.
There have been various discussion where more experienced people discussed about it, you can follow that here : for and counter argument on this SO question - Session management using Hibernate in a Swing application
Also see this on the same topic.
Here is a sample desktop application created by a committer of hibernate. Its bit old, you can get the idea.
And finally this is great article for understanding of general JPA concepts for desktop application.