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();
return users;

then I have to add


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 am a Java Champion and the author of the books "Modern Java Recipes" (O'Reilly Media), "Gradle Recipes for Android" (O'Reilly Media), and "Making Java Groovy" (Manning), as well as over a dozen video courses at Safari Books Online. I'm a regular member of the No Fluff, Just Stuff conference tour and have given talks all over the world. Through my company, Kousen IT, Inc, I've taught training courses to and worked with thousands of developers.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: