Hi, getting back into Kotlin (on the server) after...
# announcements
a
Hi, getting back into Kotlin (on the server) after being away for a while. Searching for idiomatic Kotlin examples of a basic CRUD class, without Hibernate or other ORM. Is it possible for the class to have its own .save() and .get() methods, and also to have immutable (val) internal data? (i.e. want to avoid the
var id:Int = 0
boilerplate, because once established, all values should be immutable, and no instance should ever have id = 0) Thanks 🙂
m
Take a look at spring-data-jdbc for a very nice example. It is built to accommodate Data Driven Design, fully 'understands' Kotlin, no reflection for mappings. A very clean example of what can be done when you don't support many-to-many relationships 'magically' like Hibernate/JPA does. https://spring.io/projects/spring-data-jdbc
a
hi, thanks Mike, most of what I am seeing here related to DBs are Java examples, and using Hibernate https://spring.io/guides/gs/accessing-data-mysql/
m
That's because the guide is using Spring-data-jpa, which is JPA/Hibernate. Read through the user guide for spring-data-jdbc, or give me a couple seconds. The main creator did a great presentation on it at SpringOne. He had one on Learn JPA in 60 minutes, or something like that, and he talked about spring-data-jdbc, so I then watched that, and was sold for many use cases.
Doesn't look like they have a guide yet for Spring Data JDBC. Not too surprised, as it's only been GA for a year or so at most.
a
Cool thanks. my data model is quite simple. I am just having trouble getting the class to look elegant or idiomatic, but like I said it's been a while so maybe I am mis-remembering. I hate having to use
var name = ""
, etc for class data/props when they should be immutable, just for the ability to construct and then
.get(id)
the correct instance.