DWR and Hibernate

Check-list to get DWR working with Hibernate

  1. Make sure you are happy with everything on the getting started page.
  2. Make sure your Hibernate configuration works properly outside of DWR.
  3. If you are using Spring with Hibernate then you might want to check out the Spring integration first.
  4. Configure DWR to work with Hibernate. (See below).
  5. Look at the demo pages: http://localhost:8080/[YOUR-WEBAPP]/dwr to check that your spring beans appear.

The HibernateBeanConverter

This converter is very similar to the standard BeanConverter except that we can decide what to do with lazy loaded properties.

There are 2 Hibernate converters called "hibernate2" and (predictably) "hibernate3".

Using HibernateBeanConverter may be risky for a number of reasons:

The HibernateBeanConverter tries to avoid reading from un-initialized properties. (If you just want something that blindly reads everything then just use a plain BeanConverter).

Hibernate 3 is considerably better at helping in this respect, and indeed under Hibernate 2 you may well discover that you are getting many empty beans as a result.

Session Management

If you are using Hibernate object the you need to understand that each DWR request is a new servlet request so you need to ensure that a Hibernate Session is open for you to work with.

If you are using Spring then an easy option is to use the Spring OpenSessionInViewFilter which will ensure that a Hibernate Session is open. Similar solutions are available in many frameworks.