hi, I am using Spring Data JPA and creating some e...
# spring
g
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
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
@alex Do all the JPA properties in the class that map to collumns have to be var's?
a
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
.