Kotlin v2 and Spring JPA v3.4, always reports `InstantiationException: Could not instantiate entity``

Help, anyone can help me ?

My project uses kotlin v2.1 and spring jpa v3.4!
The show code files are below, it can be built ok, but can not run



1 Like

You probably need to provide your actual code, not just a few screenshots. I can’t actually tell what’s wrong just from those screenshots.

What I do see is a java.lang.StackOverflowError: null in the stack trace, so that might be the problem? Maybe you’ve got some kind of unintentional recursion going on in your constructor?

2 Likes

OK! I fix the code of Cursor by manually.
By the way thank you very much!

I have the 3 tables no parent tables,
so I update code with parent class initlizing method
and the 3 sub-class inherit the parent;
so that jpa query by one table one time;

@MappedSuperclass
abstract class ImageAsset

@Entity
@Table(name = "t_product_images")
class ProductImageAsset : ImageAsset() {}

@Entity
@Table(name = "t_seller_images")
class SellerImageAsset : ImageAsset() {}

@Entity
@Table(name = "t_doctor_images")
class DoctorImageAsset : ImageAsset() {}