slick-pg icon indicating copy to clipboard operation
slick-pg copied to clipboard

ScalaReflectException in createCompositeArrayJdbcType

Open YanDoroshenko opened this issue 5 years ago • 4 comments

Hi, I'm getting a very weird and very long ScalaReflectException in runtime when trying to insert data into DB.

Here's the part that fails:

implicit lazy val cordialFeedVariantArrayTypeMapper: DriverJdbcType[List[CordialFeedVariant]] =
    createCompositeArrayJdbcType[CordialFeedVariant]("CordialFeedVariant").to(_.toList)

The exact point of failure is PgCompositeSupport.scala:71 (typeOf), the message is that class CordialFeedVariant is not found.

Please let me know you need any additional info. Thanks.

YanDoroshenko avatar Apr 22 '20 12:04 YanDoroshenko

I've found a workaround which is to manually create the AdvancedArrayJdbcType constructing and parsing strings manually.

YanDoroshenko avatar Apr 23 '20 11:04 YanDoroshenko

Here's related codes for createCompositeArrayJdbcType,

  def createCompositeArrayJdbcType[T <: Struct](sqlTypeName: String, cl: ClassLoader = getClass.getClassLoader)(implicit ev: u.TypeTag[T], tag: ClassTag[T]) = {
    val util = new PgCompositeSupportUtils(cl, emptyMembersAsNull)
    new AdvancedArrayJdbcType[T](sqlTypeName, util.mkCompositeSeqFromString[T], util.mkStringFromCompositeSeq[T])
  }

Maybe cordialFeedVariantArrayTypeMapper and CordialFeedVariant were loaded by different classloader.

tminglei avatar Apr 23 '20 12:04 tminglei

Try createCompositeArrayJdbcType[CordialFeedVariant]("CordialFeedVariant", classOf[CordialFeedVariant].getClassLoader)?

tminglei avatar Apr 23 '20 12:04 tminglei

Won't compile:

[error] /home/yan/git/upstart/data-feeds-svc/data-feeds-impl/src/main/scala/com/upstartcommerce/datafeeds/impl/repo/DataFeedsTables.scala:270:100: polymorphic expression cannot be instantiated to expected type;
[error]  found   : [SEQ[T]]SEQ[T] => Seq[T]
[error]  required: List[com.upstartcommerce.datafeeds.impl.repo.CordialFeedVariant] => Seq[com.upstartcommerce.datafeeds.impl.repo.CordialFeedVariant]
[error] Error occurred in an application involving default arguments.
[error]     createCompositeArrayJdbcType("CordialFeedVariant", classOf[CordialFeedVariant].getClassLoader).to(_.toList)
[error]                                                                                                    ^
[info] SEQ[T] => Seq[T] <: List[com.upstartcommerce.datafeeds.impl.repo.CordialFeedVariant] => Seq[com.upstartcommerce.datafeeds.impl.repo.CordialFeedVariant]?
[info] false

YanDoroshenko avatar Apr 23 '20 15:04 YanDoroshenko