Wednesday, July 18, 2012

Tapestry-hibernate and that ValueEncoder exception

I love tapestry5 but sometimes it just does something bad. In this instance, its a ValueEncoder error you get when your are using the default transitive dependencies from Maven. If just followed the "Using Tapestry with Hibernate" you might end up with a HTML 500 error with tapestry5 telling you about a ValueEncoder exception.

A first I thought it was my stuff (Netbeans + MSSQL + Glassfish) but I eventually figured out it wasn't by process of elimination.

The way to fix this is to change something in your POM file. Look for the hibernate dependency entry. You will notice that its using older version of hibernate.

<dependency>  
    <groupId>org.hibernate</groupId>  
    <artifactId>hibernate</artifactId>  
    <version>3.2.5.ga</version>  
</dependency>  

I just changed this to to use the newer version of the hibernate. Also changed it from hibernate to hibernate-core. So the dependency would read:
<dependency>  
    <groupId>org.hibernate</groupId>  
    <artifactId>hibernate-core</artifactId>  
    <version>4.1.4.Final</version>  
</dependency>  

It would be also a good idea to update the rest dependencies.

EDIT: Apparently the Tapestry-hibernate module doesn't like 4.1.4.Final version of Hibernate. The Hibernate Session will fail when you use it. The fix is just to revert Hibernate to anything in the 3.xx branch like 3.4.xx.