Thread Local pattern

Good day community!

I’m still trying to make mine ItMill work. Now I have the problem with ThreadLocal pattern. I’ve made as it shown in the wiki: http://dev.itmill.com/wiki/Articles/UsingHibernateWithToolkit (or in anyt other wiki). But when I run mine application using mvn jetty:run It doesn’t works with transactions at all. Ah. yeap I’m using also Spring.

Maybe there is problem in transaction management with ItMill and Spring ? Can someone point me to simple solution or any information on that ?

Thanks.

Hi,

Could you provide a little more information about what you’re trying to achieve, and how?

Are you having problems with Hibernate transactions, of Vaadin (itmill) transactions, or both? What are the symptoms?

Best Regards,
Marc

I want to use Vaadin with Spring 2.5.6 using the annotation driven configuration of spring. First of all I want to make usable @Transactional.

The problem is in general with JTA 'cause I’ve deployed mine application to tomcat 6 and still have the same problem : i.e. ThreadLocal pattern doesn’t works for me (Or maybe there is some additional configuration which I don’t read). But mine application never goes into transactionStart(Application app, Object transactionData).

I’m still not quite sure of how you have set up your application… this might be because I know virtually nothing about Spring, but: please note that Vaadin transactions do not automatically have anything to do with Spring transactions. If transactionStart() does not get called, one would imagine it’s not set up correctly - did you do something like:

MyApplication extends Application implements TransactionListener {
   public void init() {
      // ...
      getContext().addTransactionListener(this);
   }

    public void transactionStart(Application application, Object transactionData) {
        // stuff to do at start of transaction (e.g ThreadLocal pattern)
    }
    public void transactionEnd(Application application, Object transactionData) {
        // stuff to do at end of transaction
    }
}

yes


public class Desktop extends Application implements ApplicationContext.TransactionListener {

    private static ThreadLocal<Desktop> currentApplication = new ThreadLocal<Desktop>();

    public static Desktop getCurrentDesktop() {
        return currentApplication.get();
    }

    @Override
    public void transactionStart(Application application, Object transactionData) {
        System.out.println("Loading the threadlocal");
        if (application == Desktop.this) {
            System.out.println("Registering the threadLocal");
            currentApplication.set(this);
        }
    }

    @Override
    public void transactionEnd(Application application, Object transactionData) {
        if (application == Desktop.this) {
            System.out.println("Unregistering the threadLocal");
            currentApplication.remove();
        }
    }
}

But I don’t see any output in mine server

Well, the important part in the was actually this:

public void init() {
     getContext().addTransactionListener(this);
}

…but your code snippet above was probably not complete, init() is abstract, so it will not compile without it…

Let’s backtrack a little… Do you get anything at all on your screen? I.e is the application runnig normally except for the transactionListener?

Best Regards,
Marc