Skip to content

Instantly share code, notes, and snippets.

@st
Last active August 29, 2015 14:13
Show Gist options
  • Save st/c68ca56f796d04dee152 to your computer and use it in GitHub Desktop.
Save st/c68ca56f796d04dee152 to your computer and use it in GitHub Desktop.
Issue with pooled connection in Korma with Java 1.8 (mac os x yosemite)

Minimal setup to reproduce the problem. Note that that with Java 1.7 this works fine.

  $ java -version
  java version "1.8.0_40-ea"
  Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b15)
  Java HotSpot(TM) 64-Bit Server VM (build 25.40-b18, mixed mode)
  • lein new testkorma

  • Then update dependencies for "your" database:

(defproject testkorma "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [korma "0.4.0"]
                 ;; here should go the dependencies for the database you are targetting
                 [org.hsqldb/hsqldb "2.3.2"]
                 [org.xerial/sqlite-jdbc "3.7.2"]])
  • in core_test.clj:
(ns testkorma.core-test
  (:require [clojure.test :refer :all]
            [korma.db :refer [defdb]]
            [korma.core :refer :all]
            [testkorma.core :refer :all]))

(deftest a-test
  (defdb sqlite-db {
    :classname "org.sqlite.JDBC"
    :subprotocol "sqlite"
    :subname "resources/test.sqlite"
    :make-pool? true ;; Without this it works fine
    ;; but each db query reinstantiates a connection...
    })
  (defentity toto)                  ;; up to here everything is OK
  (println "select" (select toto))) ;; this will fail
  • Trace of error:
ERROR in (a-test) (ManagementFactory.java:494)
Uncaught exception, not in assertion.
expected: nil
  actual: java.lang.NoClassDefFoundError: sun/management/ExtendedPlatformComponent
 at java.lang.management.ManagementFactory.getPlatformMBeanServer (ManagementFactory.java:494)
    com.mchange.v2.c3p0.management.ActiveManagementCoordinator.<init> (ActiveManagementCoordinator.java:42)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
    sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java:62)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance (Constructor.java:422)
    java.lang.Class.newInstance (Class.java:442)
    com.mchange.v2.c3p0.C3P0Registry.<clinit> (C3P0Registry.java:134)
    com.mchange.v2.c3p0.impl.PoolBackedDataSourceBase.<init> (PoolBackedDataSourceBase.java:228)
    com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.<init> (AbstractPoolBackedDataSource.java:62)
    com.mchange.v2.c3p0.ComboPooledDataSource.<init> (ComboPooledDataSource.java:109)
    com.mchange.v2.c3p0.ComboPooledDataSource.<init> (ComboPooledDataSource.java:105)
    korma.db$connection_pool.invoke (db.clj:19)
    korma.db$delay_pool$fn__657.invoke (db.clj:53)
...
@st
Copy link
Author

st commented Jan 9, 2015

Upgrading to 8u40 Build b20 (https://jdk8.java.net/download.html) fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment