What's the best practice?
I've googled around, and there's no consensus. Everyone says something, and then takes it back. I find lugging a session around stupid...
So, what's the deal?
Why use Hibernate? Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java objects. It relieves programmer from manual handling of persistent data, hence reducing the development time and maintenance cost.
Swing is a GUI application programming interface that is included in the Java development kit. It is the javax. swing package. The old GUI API for Java was AWT. Swing is built on top of AWT, so many AWT features are found in Swing.
No, Hibernate is not deprecated.
The Hibernate architecture includes many objects such as persistent object, session factory, transaction factory, connection factory, session, transaction etc. The Hibernate architecture is categorized in four layers. This is the high level architecture of Hibernate with mapping file and configuration file.
Maybe a session per event handling is the right approach. In web applications, we usually create one session per request (using all those OpenSessionInView stuff and etc). If we think through, every request in web application is a different interaction in the application, and in a Swing application, every fired event is a different interaction in the application. If we apply the same principles we apply in web applications in Swing applications, then we should create a session per event handling.
But we must determinate if using Hibernate is the best option... The database you are accessing is a local or a remote database? Do other applications share the same database? You should consider creating an EJB\HTTP backend instead having your Swing applications directly accessing the database. Using Hibernate suggest that you have a not-so-simple database, so I think you should consider create a EJB\HTTP backend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With