Could not find or construct Composite[com.SomeCaseClass] when adding any simple type to a case class with over 35 parameters.
I have a case class for mapping rows that contains 43 fields. When I remove the last few fields so the case class only has 35 the error below goes away. When I add a 36th field to the case class with the same simple type as the 35th (Int or Option[Int] for example) the following error surfaces.
Could not find or construct Composite[com.SomeCaseClass]. If com.SomeCaseClass is a simple type (or option thereof) that maps to a single column, you're probably missing a Meta instance. If com.SomeCaseClass is a product type (typically a case class, tuple, or HList) then probably one of its component types is missing a Composite instance. You can usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in question.
Do I need to create a custom mapping or Meta instance for case classes over 35 fields?
Confoundingly, I also receive this same error when I add an identical query method. Even when the original query method works, adding an identical method with a different name leads to that error mentioned above.
Unfortunately, there's a randomness in implicit search for Composite derivation. If you can group your relevant fields into smaller case classes, the derivation steps will be much more stable:
@ import $ivy.`org.tpolecat::doobie-core:0.5.1`
import $ivy.$
@ import doobie._, doobie.implicits._
import doobie._, doobie.implicits._
@ case class Flat(
field1: Option[Int],
field2: Option[Int],
field3: Option[Int],
field4: Option[Int],
field5: Option[Int],
field6: Option[Int],
field7: Option[Int],
field8: Option[Int],
field9: Option[Int],
field10: Option[Int],
field11: Option[Int],
field12: Option[Int],
field13: Option[Int],
field14: Option[Int],
field15: Option[Int],
field16: Option[Int],
field17: Option[Int],
field18: Option[Int],
field19: Option[Int],
field20: Option[Int],
field21: Option[Int],
field22: Option[Int],
field23: Option[Int],
field24: Option[Int],
field25: Option[Int],
field26: Option[Int],
field27: Option[Int],
field28: Option[Int],
field29: Option[Int],
field30: Option[Int],
field31: Option[Int],
field32: Option[Int],
field33: Option[Int],
field34: Option[Int],
field35: Option[Int],
field36: Option[Int]
)
defined class Flat
@
@ Composite[Flat]
res4: Composite[Flat] = doobie.util.composite$LowerPriorityComposite$$anon$12@7281a0fe
@ Composite[Flat]
cmd5.sc:1: Could not find or construct Composite[ammonite.$sess.cmd3.Flat].
If ammonite.$sess.cmd3.Flat is a simple type (or option thereof) that maps to a single column, you're
probably missing a Meta instance. If ammonite.$sess.cmd3.Flat is a product type (typically a case class,
tuple, or HList) then probably one of its component types is missing a Composite instance. You can
usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in
question. See the FAQ in the Book of Doobie for more hints.
val res5 = Composite[Flat]
^
Compilation Failed
@ Composite[Flat]
cmd5.sc:1: Could not find or construct Composite[ammonite.$sess.cmd3.Flat].
If ammonite.$sess.cmd3.Flat is a simple type (or option thereof) that maps to a single column, you're
probably missing a Meta instance. If ammonite.$sess.cmd3.Flat is a product type (typically a case class,
tuple, or HList) then probably one of its component types is missing a Composite instance. You can
usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in
question. See the FAQ in the Book of Doobie for more hints.
val res5 = Composite[Flat]
^
Compilation Failed
@ Composite[Flat]
cmd5.sc:1: Could not find or construct Composite[ammonite.$sess.cmd3.Flat].
If ammonite.$sess.cmd3.Flat is a simple type (or option thereof) that maps to a single column, you're
probably missing a Meta instance. If ammonite.$sess.cmd3.Flat is a product type (typically a case class,
tuple, or HList) then probably one of its component types is missing a Composite instance. You can
usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in
question. See the FAQ in the Book of Doobie for more hints.
val res5 = Composite[Flat]
^
Compilation Failed
@ Composite[Flat]
cmd5.sc:1: Could not find or construct Composite[ammonite.$sess.cmd3.Flat].
If ammonite.$sess.cmd3.Flat is a simple type (or option thereof) that maps to a single column, you're
probably missing a Meta instance. If ammonite.$sess.cmd3.Flat is a product type (typically a case class,
tuple, or HList) then probably one of its component types is missing a Composite instance. You can
usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in
question. See the FAQ in the Book of Doobie for more hints.
val res5 = Composite[Flat]
^
Compilation Failed
@ Composite[Flat]
cmd5.sc:1: Could not find or construct Composite[ammonite.$sess.cmd3.Flat].
If ammonite.$sess.cmd3.Flat is a simple type (or option thereof) that maps to a single column, you're
probably missing a Meta instance. If ammonite.$sess.cmd3.Flat is a product type (typically a case class,
tuple, or HList) then probably one of its component types is missing a Composite instance. You can
usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in
question. See the FAQ in the Book of Doobie for more hints.
val res5 = Composite[Flat]
^
Compilation Failed
@ Composite[Flat]
cmd5.sc:1: Could not find or construct Composite[ammonite.$sess.cmd3.Flat].
If ammonite.$sess.cmd3.Flat is a simple type (or option thereof) that maps to a single column, you're
probably missing a Meta instance. If ammonite.$sess.cmd3.Flat is a product type (typically a case class,
tuple, or HList) then probably one of its component types is missing a Composite instance. You can
usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in
question. See the FAQ in the Book of Doobie for more hints.
val res5 = Composite[Flat]
^
Compilation Failed
@ Composite[Flat]
cmd5.sc:1: Could not find or construct Composite[ammonite.$sess.cmd3.Flat].
If ammonite.$sess.cmd3.Flat is a simple type (or option thereof) that maps to a single column, you're
probably missing a Meta instance. If ammonite.$sess.cmd3.Flat is a product type (typically a case class,
tuple, or HList) then probably one of its component types is missing a Composite instance. You can
usually diagnose this by evaluating Composite[Foo] for each element Foo of the product type in
question. See the FAQ in the Book of Doobie for more hints.
val res5 = Composite[Flat]
^
Compilation Failed
@ Composite[Flat]
res5: Composite[Flat] = doobie.util.composite$LowerPriorityComposite$$anon$12@5ad5fafa
@
@
@ case class Group1(field11: Option[Int], field12: Option[Int], field13: Option[Int], field14: Option[Int])
defined class Group1
@ case class Group2(field21: Option[Int], field22: Option[Int], field23: Option[Int], field24: Option[Int])
defined class Group2
@ case class Group3(field31: Option[Int], field32: Option[Int], field33: Option[Int], field34: Option[Int])
defined class Group3
@ case class Group4(field41: Option[Int], field42: Option[Int], field43: Option[Int], field44: Option[Int])
defined class Group4
@ case class Group5(field51: Option[Int], field52: Option[Int], field53: Option[Int], field54: Option[Int])
defined class Group5
@ case class Group6(field61: Option[Int], field62: Option[Int], field63: Option[Int], field64: Option[Int])
defined class Group6
@ case class Group7(field71: Option[Int], field72: Option[Int], field73: Option[Int], field74: Option[Int])
defined class Group7
@ case class Group8(field81: Option[Int], field82: Option[Int], field83: Option[Int], field84: Option[Int])
defined class Group8
@ case class Group9(field91: Option[Int], field92: Option[Int], field93: Option[Int], field94: Option[Int])
defined class Group9
@ case class Grouped(
group1: Group1,
group2: Group2,
group3: Group3,
group4: Group4,
group5: Group5,
group6: Group6,
group7: Group7,
group8: Group8,
group9: Group9
)
defined class Grouped
@ Composite[Grouped]
res40: Composite[Grouped] = doobie.util.composite$LowerPriorityComposite$$anon$12@609583a3
@ Composite[Grouped]
res41: Composite[Grouped] = doobie.util.composite$LowerPriorityComposite$$anon$12@43ababbc
@ Composite[Grouped]
res42: Composite[Grouped] = doobie.util.composite$LowerPriorityComposite$$anon$12@4467c1ed
@ Composite[Grouped]
res43: Composite[Grouped] = doobie.util.composite$LowerPriorityComposite$$anon$12@5efff063
@ Composite[Grouped]
res44: Composite[Grouped] = doobie.util.composite$LowerPriorityComposite$$anon$12@5846c70a
Is this really the solution...
Funny, got same problem, intermittently, on sbt 1.1.0. Changed sbt to 1.1.6 and it worked, although I had to increase the stack size, otherwise compiler failed with stack overflow.
Nothing fancy, just a single case class with 34 primitive fields. This issue is particullary annoying, given that circe (or most other json lib's) generic derivation works fine with large case classes.
If I have time I'll try to point scalac-profiler on my code.
This ongoing effort https://github.com/tpolecat/doobie/tree/magnolia might be the rescue.
Magnolia is definitely the way to go, doobie is the last package in our codebase using shapeless for derivation, I'm going to try a working example from that branch
I tried to rebase on 0.7.x but since Kernel and Composite got removed, where should I put the magnolia macros ? In Get and Put, or in Write and Read ?
It's basically removing all usages of shapeless.Lazy[_], right ?
The inductive derivation is for Read and Write so that's the bit you would replace.