Hi,

Short question:

is there somebody using Swing with Spring/Hibernate and long transactions and lazy loading? How?

Long question:

currently i am doing my first steps in Swing. As i understand, it is a good idea to make blocking Tasks in Background, so i try to wrap all database updates/deletes in Tasks (Tasks are a subclass of SwingWorker in the JSR 296 Swing Framework).

We are using:

Swing with JSR 296 Framework
Spring 2.0.6 for DAO support
Hibernate 3.2.5-GA

All DAOs are Spring DAO extending HibernateDaoSupport, so when my application starts, i create a Spring ApplicationContext, and every JPanel has a reference to the context. Transactions should be handled in programmatic way using a HibernateTransactionManager, not the template.

What i am trying to do is IMHO a simple application: in the main swing window you list a list of e.g. customers (some properties are lazy-loaded) - this is the parent Window. You can double-click a customer, which opens a new Swing Child Panel , locking and displaying the customer and opening a long-transaction. If you close the window with OK, customers data is saved (commited), otherwise discarded (rollback).

The first background task should be started, when i am constructing the Swing Panel with the customer. I must lock the customer, so i do a getHibernateTemplate().lock(customer, LockMode.UPGRADE), which can fail, or the customer is locked otherwhere, then i will handle this with a timeout.

The second background task is executed, when i update the customer - this results in calling some DAOs for customer, address and so on. After this task, the transaction should be commited/rollbacked.

My Problems are, that the transaction is closing the session AND, when i do the updates in the background tasks, the transaction do not work (No Hibernate Session bound to thread). So, after a transaction commit, the list isn't working proper, since there is no session (LazyLoading Exception).

Questions:

I guess, i must syncronize the transaction with this background taks using the TransactionSynchronizationManager, right?

Ideally, the session should be closed and reopend after the Parent window is disposed. How can i control the closing of a session. Is this a Managed Session in Hibernate, and how can i use it in the Spring Framework?

There is a special wiki page on Hibernate.org (http://www.hibernate.org/333.html), which is giving me a lot of Hibernate informations, but my issues seems to be more Spring-specific than Hibernate.

Really, ANY ideas, code examples and comments are welcome.

Thank you in advance.

Bart