Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slick 3.0.0 with HikariCP driver not loaded - IllegalAccessException: AbstractHikariConfig can not access a member with modifiers "private"

I am trying to use tminglei/slick-pg v9.0.0 with slick 3.0.0 and am getting an IllegalAccessException:

akka.actor.ActorInitializationException: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:166) ~[akka-actor_2.11-2.3.11.jar:na]
    ...
Caused by: java.lang.RuntimeException: driverClassName specified class 'com.github.tminglei.MyPostgresDriver$' could not be loaded
    at com.zaxxer.hikari.AbstractHikariConfig.setDriverClassName(AbstractHikariConfig.java:370) ~[HikariCP-java6-2.3.8.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$$anonfun$forConfig$18.apply(JdbcDataSource.scala:145) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$$anonfun$forConfig$18.apply(JdbcDataSource.scala:145) ~[slick_2.11-3.0.0.jar:na]
    at scala.Option.map(Option.scala:146) ~[scala-library-2.11.7.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:145) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:135) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:35) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forConfig(JdbcBackend.scala:223) ~[slick_2.11-3.0.0.jar:na]
    at slick.jdbc.JdbcBackend$$anon$3.forConfig(JdbcBackend.scala:33) ~[slick_2.11-3.0.0.jar:na]
    ...
Caused by: java.lang.IllegalAccessException: Class com.zaxxer.hikari.AbstractHikariConfig can not access a member of class com.github.tminglei.MyPostgresDriver$ with modifiers "private"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109) ~[na:1.7.0_79]
    at java.lang.Class.newInstance(Class.java:373) ~[na:1.7.0_79]
    at com.zaxxer.hikari.AbstractHikariConfig.setDriverClassName(AbstractHikariConfig.java:366) ~[HikariCP-java6-2.3.8.jar:na]
    ... 43 common frames omitted

HikariCP is the default connection pool in slick 3.0.0

I have defined the driver class much like in the example:

trait MyPostgresDriver extends ExPostgresDriver with PgArraySupport
  with PgEnumSupport
  with PgRangeSupport
  with PgHStoreSupport
  with PgSearchSupport{

  override val api = new MyAPI {}

  //////
  trait MyAPI extends API
  with ArrayImplicits
  with RangeImplicits
  with HStoreImplicits
  with SearchImplicits
  with SearchAssistants

}

object MyPostgresDriver extends MyPostgresDriver

My database config is pretty straightforward [excerpt of typesafe config follows]:

slick.dbs.default {

  driver="com.github.tminglei.MyPostgresDriver$"

  db {
    driver="org.postgresql.Driver"

    url="jdbc:postgresql://hostname:port/dbname"
    user=user
    password="pass"
  }
}

It does not seem as if it should not work, and yet...

Should I change my driver class somehow? Is it something else?

Note: as can be seen in the stacktrace I am using

  1. Java 1.7.0_79
  2. Scala 2.11.7
  3. akka 2.3.11 (I share the config instance for slick and akka)
  4. slick 3.0.0
  5. HikariCP-java6 2.3.8
  6. tminglei's slick-pg_core 0.9.0

Lastly, when debugging thru the jdk code at Class.class (decompiled line 143)

 Constructor tmpConstructor1 = this.cachedConstructor; 

I get the following (toString'ed) value (as shown by intellij):

private com.github.tminglei.MyPostgresDriver$()

Could this be indicative of the problem? If so how should I fix it?


EDIT

I have replaced the custom driver configuration with the stock PostgresDriver like so:

slick.dbs.default {

  driver="slick.driver.PostgresDriver$"

  db {
    driver="org.postgresql.Driver"

    url="jdbc:postgresql://hostname:port/dbname"
    user=user
    password="pass"
  }
}

The error is the same:

akka.actor.ActorInitializationException: exception during creation
    ...
Caused by: java.lang.RuntimeException: driverClassName specified class 'slick.driver.PostgresDriver$' could not be loaded
    ... 
Caused by: java.lang.IllegalAccessException: Class com.zaxxer.hikari.AbstractHikariConfig can not access a member of class slick.driver.PostgresDriver$ with modifiers "private"
like image 240
Yaneeve Avatar asked Jul 01 '15 07:07

Yaneeve


1 Answers

I had a similar problem.

I think you are using Database.forConfig("slick.dbs.default") but your config file is in DatabaseConfig format.

Instead, try using:

val dbConfig: DatabaseConfig[PostgresDriver] = DatabaseConfig.forConfig("slick.dbs.default")
val db = dbConfig.db
like image 177
jeckhart Avatar answered Nov 01 '22 00:11

jeckhart