Vaadin 7 on Grails 2.x
  • Introduction
  • Project setup
    • Command Line
    • IntelliJ IDEA
    • Eclipse
    • NetBeans
    • Plugin Configuration
    • Clean up
    • Best Practices
  • Database
    • GORM
      • Create Domain Model
      • Transactions
      • LazyInitializationException
      • Open Session In View I.
      • Open Session In View II.
      • Table Container
    • Groovy SQL
      • Create Sql
      • Execute SQLs
    • MyBatis
      • Configuration
      • Basics
    • JdbcTemplate
      • Create Beans
      • Usage
    • Clean Up With Alternatives
  • Architecture
    • Model View Presenter
  • Spring Autowiring
    • Create Simple Application
    • Application With Navigator
  • UI
    • Re-using GORM Validations
    • Async Push
    • Multiple application
    • SASS Compilation
    • Widgetset Compilation
  • Spring Security
    • Spring Security Dependency
    • Spring Security Basics
    • Secured Navigator
  • Localization
    • Localization Basics
    • Custom MessageSource
  • REST
    • Without using root URL
    • Using root URL for Vaadin app
  • Plugin development
    • Github
    • Development
Powered by GitBook
On this page
  • Step 1
  • Step 2

Was this helpful?

  1. Database
  2. GORM

Open Session In View II.

PreviousOpen Session In View I.NextTable Container

Last updated 5 years ago

Was this helpful?

Example code is available on .

In the previous article we have described how to enable OSIV in VaadinConfig.groovy. This tutorial will show way how to do it in the old way, without configuration.

The other way to use OSIV in Grails with Vaadin is to manually add an extra filter OpenSessionInViewFilter into web.xml file.

Step 1

Generate project templates in your project. install-templates command will generate many files inside src/templates folder.

grails install-templates

Leave only web.xml and remove folders artifacts, scaffolding and testing.

Generated templates

Step 2

Add the following filter definition, that will keep session opened during each reqiest, into generated web.xml.

<!-- OSIV Filter -->
<filter>
    <filter-name>openSessionInView</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>openSessionInView</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Change package name of OpenSessionInViewFilter for Hibernate 3 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

We are done. Now we can run the application and Hibernate session will be always opened, during each Vaadin request.

github.com/vaadin-on-grails/gorm-open-session-in-view-ii