I have a question about the session-per-conversation strategy. I am building a database application in Java SE with Hibernate, the application is build as a MDI application. The application consists of multiple Internalframes each can be used to get specific data from the database.
Now I am trying to implement a reusable session-per-conversation, but I have a little bit difficulty how to implement this and where to place the code in the internalframes. The requirements are as follows:
As I mentioned before the application is a MDI, at the moment I have a couple of internalframes, the final application will consists of more than 30 different internalframes. In every internalframe I need access to the database, the user can have multiple frames open. Finally, the user can think as long as he wants, a particular internalframe can be open for a whole day (worst case).
After reading the book from Cameron McKenzie and reading a big part from the book "Java Persistence with Hibernate" I came to the conclusion that solving this problem can best be done using the session-per-conversation. But how do I implement this without writing 30 times the same code, the latter book gives no examples about a SE application.
The book gives a example for a web application with a interceptor, is using a interceptor also a good approach in a SE application? And how do I set this up for a particular frame?
Or are there other approaches?
Thanks in advance,
Marcel van der Ven
Marcel van der Ven
Joined: Mar 20, 2010
Because I get not much respond on this topic, I have invented my own solution. The question now is, is this a good solution? Because I have not very much experience with Hibernate I hope someone here can give me some suggestions on the solution that I came up with for the session-per-conversation problem in Java SE.
I have a abstract superclass named CeInternalFrame for all my subscreens, in this abstract superclass I have added a private InternalFrameListener member, and also a getter and setter for this member.
Now in my superclass I have to implement the abstract methods from the InternalFrameListener, I implemented these in the abstract superclass.
Now for all my subscreens I set the InternalFrameListener to the listener in the superclass, using the setter in the superclass.
Now I can start a conversation when the InternalFrame is opened, commit any transactions that are open when the frame is iconified and flush the sesssion and close the conversation when the internalframe is closed. I have now one place where the code for the conversation reside.