1

I'm trying to use hibernate-shards with hibernate 4, but I'm running into a class not found error. When I run a sample application that tries to write to the sharded database, I get the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/engine/SessionFactoryImplementor
at org.hibernate.shards.ShardedConfiguration.buildSessionFactory(ShardedConfiguration.java:251)

Here is the relevant section from my Maven POM file:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.0.0.Final</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>4.0.0.Final</version>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.18</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-shards</artifactId>
    <version>3.0.0.Beta2</version>
</dependency>

Looking into the hibernate-core jar file, it appears that the package of this class is different from what hibernate-shards is expecting. It appears to now be in an spi directory.

$ jar tvf lib/hibernate-core-4.0.0.Final.jar  | grep SessionFactoryImplementor
   3049 Wed Dec 14 22:47:16 EST 2011 org/hibernate/engine/spi/SessionFactoryImplementor.class

I've found another question where people using hibernate-shards and Spring Framework have a similar issue. I'm not using Spring, so I don't think that the solution to that question will work for me.


This question's answer suggests that a fork of hibernate-shards can be used to work with the latest versions of hibernate, however the link to the fork in that answer is now an error.


I was hoping that compiling the latest version of hibernate-shards from source (cloned from github) would solve the problem. But I get the same exception when I'm using hibernate-shards-4.0.0-SNAPSHOT which I created like this:

# Get the hibernate-shards code
git clone https://github.com/hibernate/hibernate-shards.git
cd hibernate-shards

# Install the gradle build system.  The following commands are for Ubuntu
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle

# Compile the hibernate-shards project
gradle :jar :javadoc :sourcesJar
jar cf build/libs/hibernate-shards-4.0.0-SNAPSHOT-javadoc.jar -C build/docs/javadoc/ .

# Install hibernate-shards into maven
mvn install:install-file -DgroupId=org.hibernate -DartifactId=hibernate-shards -Dversion=4.0.0-SNAPSHOT -Dpackaging=jar -Dfile=build/libs/hibernate-shards-4.0.0-SNAPSHOT.jar -Djavadoc=build/libs/hibernate-shards-4.0.0-SNAPSHOT-javadoc.jar -Dsources=build/libs/hibernate-shards-4.0.0-SNAPSHOT-sources.jar

If I look at the gradle file, it is building against Hibernate 3.6.10.Final, not Hibernate 4.


Is hibernate shards just not compatible with hibernate 4 at this point?

Community
  • 1
  • 1
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109

0 Answers0