It looks like you are missing the library that Hibernate needs at runtime. I saw the same behavior as you with your code (MySQL 5, MySQL JDBC driver, Mac OS) until I changed the line:
catch (Exception e) { System.out.println(e.getMessage()); }
To:
catch (Throwable e) { e.printStackTrace(); }
Then I started to see a whole set of messages NoClassDefFoundError and ClassNotFoundError about libraries that Hibernate was looking for, but was not included in my CLASSPATH. I suspect you are missing a library that needs Hibernate, and because you are catching an Exception , not Throwable - which is catching Error - you are not seeing an error message. Cm:
Why catch Exceptions in Java when you can catch Throwables?
If you catch Throwable , you will see pretty quickly which libraries and classes you are missing: I assume that you are probably missing EHCache (which Hibernate is apparently used as the default second level cache), CGLIB / ASM or Java Transaction API If you are missing EHCache and want hibernation to use its own Hashtable cache in memory instead of EHCache, add the line below to hibernate.cfg.xml :
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
Comment based update for reply:
I do not use NetBeans, and therefore I have not encountered this problem, but it is quite common. Cm:
Error: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter. <init> (I) V
http://www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html (Report a similar problem with Hibernate and Jersey in Netbeans)
https://hibernate.onjira.com/browse/HHH-2222 (Hibernate error message mentioning this problem)
http://netbeans.org/bugzilla/show_bug.cgi?id=145589 (Netbeans error report for linked sleep mode using older versions of cglib).
The StackOverflow post related to above has quite a few details. Summarizing:
Hibernate 3.2 uses CGLib 2.1.3 to generate code at runtime, to improve performance, and to create proxies for one-to-one and one-to-many comparisons.
CGLib is a higher-level shell around ASM, a bytecode manipulation library. CGLib 2.1.3 requires ASM 1.5.3, which is binary incompatible with ASM 2.2. ASM 2.2, in turn, is a dependency for versions of Spring 2.5.
To solve these problems between Hibernate and Spring, Spring 2.5 associates its own version of asm with the name of the Spring package; later versions of Hibernate use CGLIB 2.2, which also associates its own version of ASM with a custom package name. The most recent versions of Hibernate completely eliminate CGLIB and use Javassist instead, but NetBeans still bundles Hibernate 3.2.5.
You have several options, and then:
Update Hibernate Library Package on Netbeans with CGLIB 2.2
Tell Hibernate to use Javassist to generate runtime code. Add this line to hibernate.properties or specify it as a system property using -D (you cannot specify this property in the hibernate.cfg.xml file, apparently):
hibernate.bytecode.provider=javassist
Good luck, that was a pretty interesting question!