Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScalaReflectException in createCompositeArrayJdbcType #476

Open
YanDoroshenko opened this issue Apr 22, 2020 · 4 comments
Open

ScalaReflectException in createCompositeArrayJdbcType #476

YanDoroshenko opened this issue Apr 22, 2020 · 4 comments

Comments

@YanDoroshenko
Copy link
Contributor

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
Copy link
Contributor Author

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

@tminglei
Copy link
Owner

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
Copy link
Owner

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

@YanDoroshenko
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants