tminglei / slick-pg

Slick extensions for PostgreSQL
BSD 2-Clause "Simplified" License
837 stars 180 forks source link

Version 0.16.1 Errors with Caused by: java.lang.IncompatibleClassChangeError: #403

Open dineyw23 opened 6 years ago

dineyw23 commented 6 years ago

I have updated my project to latest slick-pg version to fix #400. Queries give the following error.
build.sbt. Is this related to slick version incompatibility? I'm using Extended profile from the Readme.

  "com.typesafe.play" %% "play-slick" % "3.0.1",
  "com.typesafe.play" % "play-slick-evolutions_2.12" % "3.0.2",
  "com.typesafe.slick" %% "slick" % "3.2.3",

  //slick postgres extension for data types
  "com.github.tminglei" %% "slick-pg" % "0.16.1",
  "com.github.tminglei" %% "slick-pg_joda-time" % "0.16.1",
  "com.github.tminglei" %% "slick-pg_jts" % "0.16.1",
  "com.github.tminglei" %% "slick-pg_json4s" % "0.16.1",
  "com.github.tminglei" %% "slick-pg_play-json" % "0.16.1",
  "com.github.tminglei" %% "slick-pg_spray-json" % "0.16.1",
  "com.github.tminglei" %% "slick-pg_argonaut" % "0.16.1",
  "com.github.tminglei" %% "slick-pg_circe-json" % "0.16.1",

Error:

Caused by: java.lang.IncompatibleClassChangeError: Class com.example.pp.dao.postgres.ExtendedPostgresProfile$ does not implement the requested interface com.github.tminglei.slickpg.PgDate2Support
    at com.github.tminglei.slickpg.PgDate2Support$Date2DateTimeImplicits.$init$(PgDate2Support.scala:104)
    at com.example.pp.dao.postgres.ExtendedPostgresProfile$MyAPI$.<init>(ExtendedPostgresProfile.scala:38)
    at com.example.pp.dao.postgres.ExtendedPostgresProfile$.MyAPI$lzycompute$1(ExtendedPostgresProfile.scala:58)
    at com.example.pp.dao.postgres.ExtendedPostgresProfile$.MyAPI(ExtendedPostgresProfile.scala:58)
    at com.example.pp.dao.postgres.ExtendedPostgresProfile.$init$(ExtendedPostgresProfile.scala:36)
    at com.example.pp.dao.postgres.ExtendedPostgresProfile$.<init>(ExtendedPostgresProfile.scala:58)
    at com.example.pp.dao.postgres.ExtendedPostgresProfile$.<clinit>(ExtendedPostgresProfile.scala)
    at services.dao.promotion.participant.PromotionParticipantDAO.getPromotionParticipantLatestIteration(PromotionParticipantDAO.scala:184)
    at com.example.pp.dao.services.hystrix.promotion.participant.GetPromoParticipantLatestIterationByGuidAndCampaignIdCommand.construct(GetPromoParticipantLatestIterationByGuidAndCampaignIdCommand.scala:39)
    at com.netflix.hystrix.HystrixObservableCommand.getExecutionObservable(HystrixObservableCommand.java:252)
[info] c.z.h.p.PoolBase - db - Driver does not support get/set network timeout for connections. (Method org.postgresql.jdbc.PgConnection.getNetworkTimeout() is not yet implemented.
geekthanos commented 6 years ago

Even I am getting the same error:

[info] c.s.p.d.p.ExtendedPostgresProfile - >>> binding tsrange -> com.github.tminglei.slickpg.Range [warn] c.s.p.d.p.ExtendedPostgresProfile - >>> DUPLICATED binding for tsrange - existed: com.github.tminglei.slickpg.Range, new: com.github.tminglei.slickpg.Range !!! If it's expected, pls ignore it. [info] c.s.p.d.p.ExtendedPostgresProfile - >>> binding tstzrange -> com.github.tminglei.slickpg.Range [info] c.s.p.d.p.ExtendedPostgresProfile - >>> binding daterange -> com.github.tminglei.slickpg.Range [warn] c.s.p.d.p.ExtendedPostgresProfile - >>> DUPLICATED binding for daterange - existed: com.github.tminglei.slickpg.Range, new: com.github.tminglei.slickpg.Range !!! If it's expected, pls ignore it. [error] c.n.h.AbstractCommand - Unrecoverable Error for HystrixCommand so will throw HystrixRuntimeException and not apply fallback. java.lang.Exception: Throwable caught while executing. at com.netflix.hystrix.AbstractCommand.getExceptionFromThrowable(AbstractCommand.java:1976) at com.netflix.hystrix.AbstractCommand.wrapWithOnExecutionErrorHook(AbstractCommand.java:1490) at com.netflix.hystrix.AbstractCommand.access$1300(AbstractCommand.java:60) at com.netflix.hystrix.AbstractCommand$ExecutionHookApplication$1.onError(AbstractCommand.java:1361) at rx.internal.operators.OnSubscribeThrow.call(OnSubscribeThrow.java:44) at rx.internal.operators.OnSubscribeThrow.call(OnSubscribeThrow.java:28) at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) Caused by: java.lang.AbstractMethodError: Method com/ xyzpay/pp/dao/postgres/ExtendedPostgresProfile$MyAPI$.com$github$tminglei$slickpg$PgRangeSupport$SimpleRangeImplicits$setter$simpleLocalDateTimeRangeTypeMapper_$eq(Lslick/jdbc/JdbcType;)V is abstract at com. xyzpay.pp.dao.postgres.ExtendedPostgresProfile$MyAPI$.com$github$tminglei$slickpg$PgRangeSupport$SimpleRangeImplicits$setter$simpleLocalDateTimeRangeTypeMapper_$eq(ExtendedPostgresProfile.scala) at com.github.tminglei.slickpg.PgRangeSupport$SimpleRangeImplicits.$init$(PgRangeSupport.scala:74) at com. xyzpay.pp.dao.postgres.ExtendedPostgresProfile$MyAPI$.(ExtendedPostgresProfile.scala:38) at com. xyzpay.pp.dao.postgres.ExtendedPostgresProfile$.MyAPI$lzycompute$1(ExtendedPostgresProfile.scala:58) at com. xyzpay.pp.dao.postgres.ExtendedPostgresProfile$.MyAPI(ExtendedPostgresProfile.scala:58) at com. xyzpay.pp.dao.postgres.ExtendedPostgresProfile.$init$(ExtendedPostgresProfile.scala:36) at com. xyzpay.pp.dao.postgres.ExtendedPostgresProfile$.(ExtendedPostgresProfile.scala:58) at com. xyzpay.pp.dao.postgres.ExtendedPostgresProfile$.(ExtendedPostgresProfile.scala) at

tminglei commented 6 years ago

@dineyw23 can you provide the ExtendedPostgresProfile's codes?

dineyw23 commented 6 years ago

Sorry for not posting this earlier. Here's the ExtendedPostgresProfile:

package com.example.pp.dao.postgres

/**
  * Slick extensions for PostgreSQL, to support a series of pg data types and related operators/functions.
  */

import com.github.tminglei.slickpg._
import com.example.pp.dao.models.promotion.participant.ParticipantStatus
import play.api.libs.json.{JsValue, Json}
import slick.basic.Capability
import slick.driver.JdbcProfile

import scala.reflect.runtime.{universe => u}

trait ExtendedPostgresProfile extends ExPostgresProfile
  with PgArraySupport
  with PgDate2Support
  with PgRangeSupport
  with PgHStoreSupport
  with PgPlayJsonSupport
  with PgSearchSupport
  with PgPostGISSupport
  with PgNetSupport
  with PgLTreeSupport {
  def pgjson = "jsonb" // jsonb support is in postgres 9.4.0 onward; for 9.3.x use "json"

  // Add back `capabilities.insertOrUpdate` to enable native `upsert` support; for postgres 9.5+
  override protected def computeCapabilities: Set[Capability] =
  super.computeCapabilities + JdbcProfile.capabilities.insertOrUpdate

  override val api = MyAPI

  object MyAPI extends API with ArrayImplicits
    with DateTimeImplicits
    with JsonImplicits
    with NetImplicits
    with LTreeImplicits
    with RangeImplicits
    with HStoreImplicits
    with SearchImplicits
    with SearchAssistants {
    implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
    implicit val playJsonArrayTypeMapper =
      new AdvancedArrayJdbcType[JsValue](pgjson,
        (s) => utils.SimpleArrayUtils.fromString[JsValue](Json.parse(_))(s).orNull,
        (v) => utils.SimpleArrayUtils.mkString[JsValue](_.toString())(v)
      ).to(_.toList)
    //Enum to db mapper for participant status
    implicit val ParticipantStatusEnumMapper = MappedColumnType.base[ParticipantStatus, String](_.name, ParticipantStatus.valueOf _)
  }
}

object ExtendedPostgresProfile  extends ExtendedPostgresProfile
tminglei commented 6 years ago

@dineyw23 can you try to change object MyAPI to trait MyAPI

dineyw23 commented 6 years ago

Just changed object MyAPI to trait MyAPI:

override val api = new MyAPI {}

trait MyAPI extends API with ArrayImplicits

It compiles fine. Execution gives the following error. The above posted ExtendedPostgresProfile code works fine with version 0.15.4:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.example.pp.dao.postgres.ExtendedPostgresProfile$
tminglei commented 6 years ago

@dineyw23 when I pasted the codes to the example project play-slick-example, and use it to replace the MyPostgresDriver, it works well. (p.s. I updated the slick-pg dependencies to version 0.16.1)

To dig into your issue, maybe you need create a sample project to help reproduce it.

yadavan88 commented 6 years ago

I am getting the same error. I was previously getting AbstractMethodError as mentioned in https://github.com/tminglei/slick-pg/issues/387. But once I made it as trait + object, that error got resolved, but got IncompatibleClassChangeError. I am using 0.16.1 version. Any Idea how to solve it ?

Received exception :

Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface com.reactore.module.entity.CustomPostgresDriver, but class was expected

tminglei commented 6 years ago

@yadavan88 you'd better provide a reproducable example project to allow mu to dig into, since it looks good in my test cases.

yadavan88 commented 6 years ago

@tminglei Sure, I will create a reproducable code and provide it.

yadavan88 commented 6 years ago

@tminglei I am not able to reproduce in a new project. I think it is some slick version mismatch. Will try to upgrade the libraries in my application to latest and check if the issue still persist or not. Thanks for the response.

tminglei commented 6 years ago

@yadavan88 ok. You're welcome!