The new Hibernate version, 3.2, is now available. The formal announcement came on 10/16.

I haven’t played with it a lot yet, of course, but one thing strikes me right away. If there are significant differences between 3.2 and the 3.1 version I’ve been using for months, I don’t see them. They may have made many fixed under the hood, but even the file system structure and the demos are all the same. At this point I don’t know what all the fuss was about.

The biggest lack from my point of view is that the Hibernate interfaces still don’t use Java 5 generics. In other words, query.list() still returns a List of Object, as I mentioned in an earlier post. That means that if I writes something like:

public List<User> findAllUsers() {
SessionFactory factory = ...;
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
Query q = session.createQuery("from User");
List<User> users = q.list();
tx.commit();
session.close();
return users;
}

then I have to add

@SuppressWarnings("unchecked")

to the method because of the cast from List to List<User>. It does work, though, so that’s good, but I think that worked with 3.1 as well.

The other thing I learned playing with the new distribution (and again this probably worked with 3.1 as well — I just didn’t realize it), is that I can use a parameterized Set as an attribute with the associated get and set methods and it all works. For example, if the User class has an attribute that is a Set of Role references, it’s okay for me to write

public class User {
Set<Role> roles = new HashSet<Role>();
public Set<Role> getRoles() { return roles; }
public void setRoles(Set<Role> roles) { this.roles = roles; }
...
}

It all comes out okay. I always thought I had to use a regular old Set rather than a parameterized one, but as they say, that turns out not to be the case. Good news.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.