I read that specifying optional = false in the @ManyToOne association annotation could help Spring improve the performance of the queries.
In a Kotlin data class entity, do I actually need to specify the parameter in the annotation, or can Spring figure this out by itself using the nullability of the item field?
For instance, if I have the following declaration:
@Entity
@Table(name = ACCESS_LOGS_ARCHIVES_TABLE, indexes = [
Index(name = "access_logs_archives_item_idx", columnList = "access_item_id")
])
data class AccessLogArchive(
val date: LocalDate,
@ManyToOne(optional = false)
@JoinColumn(name = "access_item_id", nullable = false)
val item: AccessLogItem,
val occurrences: Int
) {
@Id
@GeneratedValue
var id: Long? = null
}
@Entity
@Table(name = ACCESS_ITEMS_TABLE)
data class AccessLogItem(
@Column(length = 3) val code: String,
@Column(columnDefinition = "text") val path: String,
@Column(length = 10) val verb: String
) {
@Id
@GeneratedValue
var id: Long? = null
}
In this case, I would for instance expect Spring to know that the item field is not nullable, and thus the relationship should be understood as optional=false even without specifying it as I did. Is this the case?
Same question goes for the @JoinColumn's nullable = false, by the way.