Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you're missing a library that Hibernate needs at run time. I saw the same behavior as you with your code (MySQL 5, MySQL JDBC driver, Mac OS) until I changed the line:</p> <pre><code>catch (Exception e) { System.out.println(e.getMessage()); } </code></pre> <p>To:</p> <pre><code>catch (Throwable e) { e.printStackTrace(); } </code></pre> <p>I then started seeing a whole set of <code>NoClassDefFoundError</code> and <code>ClassNotFoundError</code> messages about libraries that Hibernate was looking for but were not included in my CLASSPATH. I suspect that you're missing a library that Hibernate needs, and because you're catching <code>Exception</code> and not <code>Throwable</code> - which catches <code>Error</code> - you're not seeing the error message. See:</p> <p><a href="https://stackoverflow.com/questions/581878/why-catch-exceptions-in-java-when-you-can-catch-throwables">Why catch Exceptions in Java, when you can catch Throwables?</a></p> <p>If you catch the <code>Throwable</code> you'll see fairly quickly what libraries and classes you're missing: my guess would be that you're probably missing EHCache (which Hibernate seems to use as a second-level cache by default), CGLIB/ASM, or the Java Transaction API. If you're missing EHCache and you want hibernate to use its own, in-memory Hashtable cache instead of EHCache, add the line below to <code>hibernate.cfg.xml</code>:</p> <pre><code>&lt;property name="hibernate.cache.provider_class"&gt;org.hibernate.cache.HashtableCacheProvider&lt;/property&gt; </code></pre> <p><strong>Update, based on comments to answer:</strong></p> <p>I don't use NetBeans and so I haven't run into this problem, but it appears fairly widespread. See:</p> <p><a href="https://stackoverflow.com/questions/2432471/error-java-lang-nosuchmethoderror-org-objectweb-asm-classwriter-initiv">Error : java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.&lt;init&gt;(I)V</a></p> <p><a href="http://www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html" rel="nofollow noreferrer">http://www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html</a> (Reports a similar problem with Hibernate and Jersey in Netbeans)</p> <p><a href="https://hibernate.onjira.com/browse/HHH-2222" rel="nofollow noreferrer">https://hibernate.onjira.com/browse/HHH-2222</a> (Hibernate bug report mentioning this problem)</p> <p><a href="http://netbeans.org/bugzilla/show_bug.cgi?id=145589" rel="nofollow noreferrer">http://netbeans.org/bugzilla/show_bug.cgi?id=145589</a> (Netbeans bug report for bundled Hibernate using older versions of cglib).</p> <p>The StackOverflow post linked to above has quite a lot of detail. To summarize:</p> <ul> <li><p>Hibernate 3.2 uses CGLib 2.1.3 for run-time code generation, to improve performance and to generate proxies for one-to-one and one-to-many mappings. </p></li> <li><p>CGLib is a higher-level wrapper around ASM, a bytecode manipulation library. CGLib 2.1.3 requires ASM 1.5.3, which is <strong>binary incompatible</strong> with ASM 2.2. ASM 2.2 in turn is a dependency for Spring versions &lt; 2.5.</p></li> <li><p>To resolve these problems between Hibernate and Spring, Spring 2.5 bundles its own version of asm with a spring package name; later versions of Hibernate use CGLIB 2.2, which also bundles its own version of ASM with a custom package name. The most recent versions of Hibernate do away with CGLIB altogether and use Javassist instead, but NetBeans still bundles Hibernate 3.2.5.</p></li> </ul> <p>You have a few options, then:</p> <ul> <li><p>Update the Hibernate library package in Netbeans with CGLIB 2.2</p></li> <li><p>Tell Hibernate to use Javassist for runtime code generation. Add this line to hibernate.properties, or specify it as a system property using -D (you can't specify this property in hibernate.cfg.xml, apparently): </p> <p><code>hibernate.bytecode.provider=javassist</code></p></li> </ul> <p>Good luck, this has been rather an interesting question!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload