Hey! This is my entity code in kotlin/springboot ...
# spring
s
Hey! This is my entity code in kotlin/springboot
Copy code
@Entity
@Table(name = "\"User\"")
class User(
    @Id
    @Column(nullable = false, updatable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Int,

    @Column(nullable = false)
    val name: String,

    @Column(nullable = false)
    val email: String,

    @Column(nullable = false)
    val password: String,

    @Column(nullable = false)
    val mobile: String,

    @Column(nullable = false)
    val role: String,

    @Column(nullable = false)
    val companyName: String,

    @Column(nullable = false)
    val address: String,

    @Column(nullable = false)
    val billingAddress: String,

    @Column
    val isDeleted: LocalDateTime,
)
The error I am getting is
org.hibernate.InstantiationException: No default constructor for entity
. Can someone assist me to solve this.
e
apply the kotlin spring boot plugin
s
this one?
Copy code
plugins {
    id("org.jetbrains.kotlin.plugin.allopen") version "1.9.22"
}
e
kotlin("plugin.spring") version "1.9.22"
If you add that one, you can remove allOpen, it's added automatically by the spring plugin
s
Thank you for your response!!
s
plugin.spring
would just open classes annotated with Spring bean annotations
@Component
,
@Service
etc, it will not help you with this particlar issue. To ensure default empty constructor is generated for JPA entities you would need to use
plugin.jpa
. Take a look at this guide: https://spring.io/guides/tutorials/spring-boot-kotlin/ also, don't skip Persistence with JPA part, as opening JPA classes is needed for lazy fetching to work properly
s
Sure, taking look now
Adding this
_kotlin_("plugin.jpa") _version_ "1.9.22"
has solved the error. Thank you!
e
Sorry, mixed them up 🙂
Spring wraps allOpen, JPA wraps noArg..
✅ 2
k
val id
is working?
s
yes it is working