I Have Joined the ThoughtWorks Camp

I have some good news: I am going to be a ThoughtWorker. After two or three weeks of interviews, I have recently accepted their offer and going to start with the company in August.

I am really looking forward to it, since many bright, passionate and talented people work for ThoughtWorks. The company is known for its cutting-edge technology development and being one of the global leaders in enterprise Agile development services. In other words, I am really happy :)

I will keep writing updates from time to time about my experience at ThoughtWorks. Stay tuned.

Write Operations in DWR

Write operations are not allowed with the default session setting for the OpenViewInSession filter which is commonly defined in web.xml as a hibernate filter. If you want to enable write operations when using DWR (Direct Web Remoting), one of the ways is to declare a filter for DWR urls. Put the following configuration in your web.xml, also please note the url pattern in filter-mapping element.


<filter>
<filter-name>dwrWriteHibernateFilter</filter-name>
<filter-class>
some.package.name.OpenWriteSessionInViewFilter
</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>dwrWriteHibernateFilter</filter-name>
<url-pattern>*.dwr</url-pattern>
</filter-mapping>

The filter class as follows:

// more imports
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;

public class OpenWriteSessionInViewFilter extends OpenSessionInViewFilter {

protected Session getSession(SessionFactory sessionFactory)
throws DataAccessResourceFailureException {
Session session = super.getSession(sessionFactory);
session.setFlushMode(FlushMode.COMMIT);
return session;
}

protected void closeSession(Session session, SessionFactory factory) {
session.flush();
super.closeSession(session, factory);
}
}