Vaadin + TabSheet + Grails Service Thread Problem

Good evening. I am having a problem using Vaadin and the tabsheet component combined with a Grails service.

Here is what i am trying to do. I have a Vaadin UI that has a tabsheet as its main component, and two different tabs inside of it where i put some components: the first tab has a VerticalLayout with other nested components and the second tab has a formlayout as its root, and other visual components nested inside.

Now, what i want to do is whenever one switches from the first tab to the second one, data for the components in the second tab, which are persisted in a database, is loaded using a Grails Service and assigned to the components inside. To be specific, i just want an inlinedatefield and a slider value to be loaded with previously saved data whenever i switch to the second tab that contains said components. In order to implement this, i coded the addSelectedTabChangeListener and inside i called my service in order to populate the components of the second tab with the needed data.

But, whenever i switch to the second tab i get the following exception:

| Error 2015-11-14 00:43:36,072 [http-bio-8080-exec-8]
ERROR server.DefaultErrorHandler -
Message: org.springframework.dao.DataAccessResourceFailureException: Could not obtain current Hibernate Session; nested exception is org.hibernate.HibernateException: No Session found for current thread

I inject, inside my application UI, the service needed to get the data required by the components in the second tab, using the @AutoWired annotation. The exception above leads me to believe that switching to another tab, in fact, creates another thread and this causes problems for the service as, apparently, the hibernate session gets trashed.

Here is the problematic piece of code:

[code]
tabSheet.addSelectedTabChangeListener(new TabSheet.SelectedTabChangeListener() {
@Override
void selectedTabChange(TabSheet.SelectedTabChangeEvent selectedTabChangeEvent) {

            if(selectedTabChangeEvent.tabSheet.selectedTab.caption == "Programación de la Notificación") {
                def savedNotificationProgramming = notificationProgrammingService.getNotificationProgramming()
                GregorianCalendar savedTime = new GregorianCalendar()
                savedTime.set(java.util.Calendar.HOUR_OF_DAY, savedNotificationProgramming?.hour)
                savedTime.set(java.util.Calendar.MINUTE, savedNotificationProgramming?.minute)
                println("hora: " + savedNotificationProgramming?.hour + "minuto: " + savedNotificationProgramming?.minute)
                jobSettingsForm.numberOfDays.value = savedNotificationProgramming?.days as Double
                jobSettingsForm.time.value = savedTime.time
            }

        }
    })

[/code]jobSettingsForm is a class that derives from FormLayout, and it is the one that becomes the root component of the second tab as its main container.

notificationProgrammingService is my grails service that i am injecting in MyUI app:

[code]
class MyUI extends UI {

@Autowired
NotificationProgrammingService notificationProgrammingService

[/code]Take note that i have another injected service that works flawlessly for a calendar component that i have on the first tab. So i know it’s not got to do with incompatibilities between Grails services and Vaadin, or a problem with the @AutoWired annotation. It has to do with the changing from one tab to another and the hibernate session being discarded.

I greatly appreciate any help i could get with this problem. I just haven’t been able to find enough information as to why this is happening. Thank you in advance