Hi folks,
I'm a Hibernate noob trying to get my feet wet.
I'm getting an error trying to invoke the config.buildSessionFactory() method. It's returning a "java.lang.NoSuchMethodError: org.hibernate.util.SoftLimitMRUCache.<init>(I)V" exception.
Prior to getting this error, I was able to make some progress learning Hibernate. I have been able to successfully create a Java class from my Hibernate mapping document (.hbm.xml) and also create a database table using the Hibernate XML configuration file (hibernate.cfg.xml). This was done using the HibernateToolTask in Ant.
I'm using the following versions:
Eclipse Java EE IDE for Web Developers Helios SR 2 (v. 3.6.2)
Ant v1.8.2
Java JDK 1.6.0_24
HibernateTools-3.2.4.GA-R200905070146-H18
hibernate-distribution-3.6.2.Final
HSQL Database Engine 2.1.0
Windows XP
As you can see, I'm starting with some example code from the Harnessing Hibernate book:
Code:
package com.oreilly.hh.data;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class MusicLibraryUtilities {
public static boolean addTrack(Track track) {
// initialize the return value as false
boolean saved = false;
// Create a configuration based on the hibernate.cfg.xml
Configuration config = new Configuration();
config.configure();
// Get the Session Factory we can use for persistence
SessionFactory sessionFactory = config.buildSessionFactory();
// Ask for a Session using the JDBC information we've configured
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
// Create some data and persist it
tx = session.beginTransaction();
session.save(track);
// We're done; make our changes permanent
tx.commit();
saved = true;
} catch (Exception e) {
if (tx != null) {
// Something went wrong; discard all partial changes
tx.rollback();
}
} finally {
// No matter what, close the session
session.close();
}
// Clean up after ourselves
sessionFactory.close();
return saved;
}
}
When I run a JUnit test class that invokes this addTrack method, I get the following stack trace. I get the same error when I run the JUnit test in Ant or when I have Eclipse run it.
Quote:
java.lang.NoSuchMethodError: org.hibernate.util.SoftLimitMRUCache.<init>(I)V
at org.hibernate.search.filter.MRUFilterCachingStrategy.initialize(MRUFilterCachingStrategy.java:36)
at org.hibernate.search.impl.SearchFactoryImpl.buildFilterCachingStrategy(SearchFactoryImpl.java:329)
at org.hibernate.search.impl.SearchFactoryImpl.<init>(SearchFactoryImpl.java:102)
at org.hibernate.search.impl.SearchFactoryImpl.getSearchFactory(SearchFactoryImpl.java:172)
at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:44)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1983)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.oreilly.hh.data.MusicLibraryUtilities.addTrack(MusicLibraryUtilities.java:19)
at com.oreilly.hh.data.CreateTracksTest.testSetTitle(CreateTracksTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Below is the classpath that Ant is using when running the build.xml. I'm starting to wonder do I really need all of these Hibernate related jars?
Code:
print.classpath:
[echo] The classpath is set to the following:
[echo] C:\dev\source_code\HarnessingHibernate\examples\ch02\src
[echo] C:\dev\source_code\HarnessingHibernate\examples\ch02\classes
[echo] C:\dev\source_code\HarnessingHibernate\examples\ch02\lib\hsqldb.jar
[echo] C:\dev\source_code\HarnessingHibernate\examples\ch02\lib\junit.jar
[echo] C:\dev\source_code\HarnessingHibernate\examples\ch02\lib\org.hamcrest.core_1.1.0.v20090501071000.jar
[echo] C:\dev\source_code\HarnessingHibernate\examples\ch02\lib\slf4j-simple-1.6.1.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\hibernate-testing.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\hibernate3.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\bytecode\cglib\cglib-2.2.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\bytecode\javassist\javassist-3.12.0.GA.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\jpa\hibernate-jpa-2.0-api-1.0.0.Final.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\optional\c3p0\c3p0-0.9.1.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\optional\ehcache\ehcache-1.5.0.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\optional\infinispan\infinispan-core-4.2.1.CR1.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\optional\jbosscache\jbosscache-core-3.2.1.GA.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\optional\oscache\oscache-2.1.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\optional\proxool\proxool-0.8.3.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\optional\swarmcache\swarmcache-1.0RC2.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\required\antlr-2.7.6.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\required\commons-collections-3.1.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\required\dom4j-1.6.1.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\required\javassist-3.12.0.GA.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\required\jta-1.1.jar
[echo] C:\dev\plugins\hibernate-distribution-3.6.2.Final\lib\required\slf4j-api-1.6.1.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse.console_3.2.4.GA-R200905070146-H18\org.hibernate.eclipse.console.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse.help_3.2.4.GA-R200905070146-H18\help.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse.jdt.apt.ui_3.2.4.GA-R200905070146-H18.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse.jdt.ui_3.2.4.GA-R200905070146-H18.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse.mapper_3.2.4.GA-R200905070146-H18\org.hibernate.eclipse.mapper.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\annotations\ejb3-persistence.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\annotations\hibernate-annotations.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\annotations\hibernate-commons-annotations.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\annotations\hibernate-entitymanager.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\annotations\hibernate-search.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\annotations\hibernate-validator.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\annotations\lucene-core-2.2.0.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\bsh-core-2.0b4.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\antlr-2.7.6.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\asm-attrs.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\asm.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\c3p0-0.9.1.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\cglib-2.1.3.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\commons-collections-2.1.1.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\commons-logging-1.0.4.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\concurrent-1.3.2.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\connector.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\dom4j-1.6.1.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\ehcache-1.2.3.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\hibernate3.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jaas.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\javassist.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jboss-cache.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jboss-common.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jboss-jmx.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jboss-system.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jdbc2_0-stdext.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jgroups-2.2.8.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\jta.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\log4j-1.2.15.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\oscache-2.1.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\proxool-0.8.3.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\hibernate\swarmcache-1.0rc2.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\tools\bsh-2.0b1.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\tools\freemarker.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\tools\hibernate-tools.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\lib\tools\jtidy-r8-20060801.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.hibernate.eclipse_3.2.4.GA-R200905070146-H18\org.hibernate.eclipse.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.jboss.tools.hibernate.jpt.core_3.2.4.GA-R200905070146-H18.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.jboss.tools.hibernate.jpt.ui_3.2.4.GA-R200905070146-H18.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.jboss.tools.hibernate.ui.veditor_3.2.4.GA-R200905070146-H18\orm2-veditor.jar
[echo] C:\dev\plugins\HibernateTools-3.2.4.GA-R200905070146-H18\plugins\org.jboss.tools.hibernate.ui.view_3.2.4.GA-R200905070146-H18\view.jar
BUILD SUCCESSFUL
Any advice is greatly appreciated and I'm happy to add any other info that may be helpful.