andreas_eriksson wrote:
Is there on the agenda to provide an example desktop application using Spring and Hibernate2 framework? The only demo application I've seen involves web components which in turn handles sessions a bit different.
From a Spring middle tier point of view, desktop applications are not that different from web applications. As section 8 of the article shows, you can load a Spring XML application context definition with multiple ApplicationContext implementations, e.g. within a web app or from a file or from the classpath. As long as you don't define web-dependent beans, such a context and its beans can be reused in any environment.
Obviously, a middle tier within a desktop application cannot have dependencies on a J2EE container. So a JndiObjectFactoryBean definition for fetching a DataSource from the container's JNDI needs to be replaced with with a local DataSource definition (I've just added a respective example to section 2 of the article).
A desktop application will also need to use HibernateTransactionManager as transaction strategy, as the container's JTA subsystem is obviously not available. In all other respects, the middle tier will behave the same: For example, a Hibernate Session will always be bound to the lifetime of a transaction. In a desktop application, there will only be one main thread with one transaction at the same time, but that doesn't matter.
The typical scope of a transaction is a method invocation on a business facade, matching declarative transactions via AOP proxies nicely, and being particularly appropriate for server applications. You can define any scope programmatically via TransactionTemplate though, even spanning user think time in a desktop application.
Juergen