NoSuchMethodError: com.j256.ormlite.db.DatabaseType.setDriver

199 views
Skip to first unread message

cre...@thoughtworks.com

unread,
Jun 12, 2013, 8:49:06 AM6/12/13
to ormlit...@googlegroups.com
Hey there! Please pardon my copy paste from stackoverflow:

I'm trying to set up a very simple ormlite stack with embedded h2. The app blows up due to aNoSuchMethodError in ormlite:

Caused by: java.lang.NoSuchMethodError: com.j256.ormlite.db.DatabaseType.setDriver(Ljava/sql/Driver;)V
    at com.j256.ormlite.jdbc.JdbcConnectionSource.initialize(JdbcConnectionSource.java:133)
    at com.j256.ormlite.jdbc.JdbcConnectionSource.<init>(JdbcConnectionSource.java:112)
    at com.j256.ormlite.jdbc.JdbcConnectionSource.<init>(JdbcConnectionSource.java:70)
    at com.sgrailways.resteasy.repositories.LocomotivesRepository.<init>(LocomotivesRepository.java:20)

Bringing up the source for ormlite says that databaseType.loadDriver(); has an unhandedClassNotFound exception and databaseType.setDriver(DriverManager.getDriver(url));(the line its actually complaining about) cannot resolve the method setDriver().

Is there something obvious I'm missing here? Perhaps a missing classpath dependency? More details follow:

Here's my Repository:

package heyworld.resteasy.repositories;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
import com.j256.ormlite.db.H2DatabaseType;
import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.support.ConnectionSource;
import heyworld.resteasy.model.Locomotive;

import java.sql.SQLException;
import java.util.List;

public class LocomotivesRepository {
    private Dao<Locomotive, Integer> locomotiveDao;
    String databaseUrl = "jdbc:h2:mem:locomotives";

    public LocomotivesRepository() {
        ConnectionSource connectionSource = null;
        try {
            connectionSource = new JdbcConnectionSource(databaseUrl, new H2DatabaseType());
             locomotiveDao = DaoManager.createDao(connectionSource, Locomotive.class);

        } catch (SQLException e) {
            e.printStackTrace();  
        }
    }

    public List<Locomotive> list() {
        try {
            return locomotiveDao.queryForAll();
        } catch (SQLException e) {
            e.printStackTrace();
            return list();
        }
    }
}

And my build.gradle:

apply plugin: "war"
apply plugin: "idea"
apply plugin: "tomcat"
apply plugin: 'h2'


buildscript {
    repositories {
        mavenCentral()
        add(new org.apache.ivy.plugins.resolver.URLResolver()) {
            name = 'GitHub'
            addArtifactPattern 'http://cloud.github.com/downloads/[organisation]/[module]/[module]-[revision].[ext]'
        }
    }

    dependencies {
        classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.8'
        classpath 'jamescarr:h2-gradle-plugin:0.8.2'
        classpath 'com.h2database:h2:1.3.164'
    }
}

repositories {
    maven {
        url "http://repository.jboss.org/maven2"
    }
    maven {
        url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases"
    }
    mavenCentral()
}

dependencies {
    providedCompile "javax.servlet:javax.servlet-api:3.0.1"
    compile "org.jboss.resteasy:resteasy-jaxrs:2.3.5.Final"
    compile "org.jboss.resteasy:resteasy-jackson-provider:2.3.5.Final"
    compile "org.jboss.resteasy:resteasy-guice:3.0-rc-1"
    compile "com.j256:ormlite:3.0"
    compile "com.j256.ormlite:ormlite-core:4.45"
    compile "com.j256.ormlite:ormlite-jdbc:4.45"
    compile "com.google.inject:guice:3.0"

    def tomcatVersion = '7.0.39'
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
    tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
        exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
    }
}

tomcatRun.doFirst {
    h2start.execute()
}

h2 {
    tcpPort = 9092
    webPort = 8082

    example {
        scripts = [
                'src/test/resources/locomotives.sql'
        ]
    }
}

cre...@thoughtworks.com

unread,
Jun 12, 2013, 9:30:38 AM6/12/13
to ormlit...@googlegroups.com
Got it. Having both compile "com.j256:ormlite:3.0" and compile "com.j256.ormlite:ormlite-core:4.45" seems to mess things up. Deleting compile "com.j256:ormlite:3.0" fixed it.
Reply all
Reply to author
Forward
0 new messages