Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate + Swing

What's the best practice?

  • A single session for the whole app
  • A session per window
  • A session per thread, and detaching everything at random
  • Something else?

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?

like image 348
Tordek Avatar asked May 18 '09 01:05

Tordek


People also ask

What is use of Hibernate?

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.

What is swing in JDBC?

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.

Is Hibernate deprecated?

No, Hibernate is not deprecated.

What is the architecture of Hibernate?

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.


1 Answers

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.

like image 155
razenha Avatar answered Oct 18 '22 01:10

razenha