Hello guys. Did anybody have a problem with `@Gene...
# micronaut
a
Hello guys. Did anybody have a problem with
@GeneratedValue
? I'm using Micronaut Data with R2DBC. I have a class:
Copy code
data class Product(
    @Id
    @GeneratedValue
    var id: Long? = null,
    val publicId: UUID,
    val code: String,
    ...
)
When I'm trying to save a new record (
id = null
) with
repository.save(product)
the exception has thrown...
Copy code
null value in column "id" of relation "products" violates not-null constraint
I'm not sure what is wrong...
b
I don't use it, but remember when I tested it briefly that I sent in a random UUID into the entity, since I wanted to keep it not nullable. And when I called save, it returned with a new generated Id from the repo. So when calling
save
it always generates a new UUID, but on
update
it uses it. But yeah, it's not a perfect match to always be forced to have a random value in it. Disclaimer, I haven't tested any further than passing by.
a
It was my mistake. I had to use auto generated primary key column in definition of the table. 🤷‍♂️