https://kotlinlang.org logo
#spring
Title
# spring
g

gbaldeck

02/21/2020, 9:45 PM
hi, I am using Spring Data JPA and creating some entities. I have the kotlin jpa plugin installed in Gradle so it should be making no-arg constructors for my entities. But I still get the error below in IntelliJ. Is there a project setting I need to change so IntelliJ recognizes I'm using the kotlin jpa plugin?
a

alex

02/23/2020, 8:32 PM
Few tips: • do not use
data class
, use
class
instead (generated equals/hashCode are not really suitable for JPA, it's always the best to define them yourself) • id must be nullable as well as
var
, also you can make it a class property, rather than constructor parameter (there is no point in making it class-level parameter)
g

gbaldeck

02/24/2020, 9:35 PM
@alex Do all the JPA properties in the class that map to collumns have to be var's?
a

alex

02/24/2020, 9:49 PM
Everything, except
@Id
annotation (and few others, like
@CreatedBy
), is managed by end user, so this decision is all yours. If data definitely immutable, then you can use `val`(which is a rare case, if you think about it), otherwise
var
.
5 Views