New Hibernate version is here

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.

About Ken Kousen
I teach software development training courses. I specialize in all areas of Java and XML, from EJB3 to web services to open source projects like Spring, Hibernate, Groovy, and Grails. Find me on Google+ I am the author of "Making Java Groovy", a Java / Groovy integration book published by Manning in the Fall of 2013, and "Gradle Recipes for Android", published by O'Reilly in 2015.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: