-
So I essentially have an entity that looks like this in Hibernate ORM (with kotlin): @Entity
@Immutable
@IdClass(AssignmentConfigId::class)
class AssignmentConfig(
@Id
@field:ManyToOne(fetch = FetchType.EAGER)
var assignmentProfile: AssignmentProfile,
@field:NotBlank(message = "Configuration cannot be null or blank")
@field:Column(updatable = false, columnDefinition = "JSON")
var config: String,
) {
@CreationTimestamp
lateinit var created: Instant
@field:Id
@field:Min(1, message = "Revision must be greater than or equal to 1")
var revision: Int = 1
} The primary key is a combination of the revision and the profile backreference. There is a lot of advantages for our project with doing this rather than using a UUID, so we'd really prefer to use a compound key like this. The problem is that we want to autoincrement the revision within the same Is there any way that we could either:
We would really appreciate any help or pointers on this. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
Hello @LarsSven, since the column is populated by a database-side trigger, you should be able to simply annotate your |
Beta Was this translation helpful? Give feedback.
So there's a couple of things going on here:
@GeneratedValue
, which has a totally different meaning from@Generated
. The first annotation uses a specific on-execution generator that, if no explicit value is specified, defaults toGenerationType.AUTO
which will in turn choose a suited automatic identifier generation strategy for your database. The@Generated
annotation instead implies the value is created on the database-side and that Hibernate should retrieve it after mutating the table.@Generated
you got the errorProperty of on-ex…