how do you write entities in kotlin? i don't want...
# spring
t
how do you write entities in kotlin? i don't want ti declare any properties that are not nullable from a domain perspective nullable but OTOH also do not have default values for them hence i'd have to declare those variables in the primary constructor. But again this is not possible as spring data needs a parameterless constructor
t
that is not true, constructor does not have to be parameterless.
Copy code
@Entity(name = "participant")
class Participant(
	@Column(name = "member_uid")
	var memberUid: String,
	@Column(name = "project_uid")
	var projectUid: String,
	@Column(name = "company_uid")
	var companyUid: String
...
)
this is a real life entity we use in production
I think in kotlin you get the benefit of constructor overload, so the default constructor is created (just not by you). Don't quote me on this, I most probably am wrong.
also, there is
import org.springframework.data.annotation.PersistenceConstructor
, but I only used it java so far when I don't want the empty constructor
d
That only works if you have the noarg plugin, which generates the no-argument constructor for you
t
Stop using ORM for non simple stuff
t
@diesieben07 that is true, forgot I have that as well. thanks for pointing it out
t
oh cool i wasn;t aware of taht plugin. looks like that could solve all the problems 🙂
t
you can get more info https://spring.io/guides/tutorials/spring-boot-kotlin/#_persistence_with_jpa (also in the topic of the channel)
t
thanks!
j
You can also use lateinit var.