To use spring persistence but maintain immutable types I've added the PersistenceConstructor annotation to my data classes. This tells spring to use that constructor when loading classes from the database.
However, I'm having trouble getting spring to find the constructor.
data class MyData @PersistenceConstructor constructor(@Id val id: Int? = null, val a:String)
This works 100% of the time on my machine but when deployed to heroku it consistently fails.
It looks like, by having default values for parameters kotlin generates more than one constructors but the problem is that each constructor get the annotation applied to them so it's just luck (or jdk implementation specific) which one spring picks up. The default one has no names for the parameters so Spring doesn't know what to do with it.
My real constructors are larger than this so it would be a pain to not have default values. Is there a way to get the annotation to only apply to the constructor without default values?