Как JPA-объявить составной ключ с Quarkus?
Попытка использовать несколько аннотаций @Id
в классе @Entity
с Quarkus, приводит к ошибке:
Currently the @Id annotation can only be placed on a single field or method. Offending class is abc.model.Property
at io.quarkus.spring.data.deployment.generate.StockMethodsAdder.getIdAnnotationTargetRec(StockMethodsAdder.java:940)
Но сначала, после объявления
interface PropertyRepository : CrudRepository<Property, Pair<String, abc.model.Entity>>
Без вышеуказанного заявления нареканий нет, но нет возможности активно управлять экземплярами Property
.
Как обойти эту ошибку?
Я имею дело с двумя сущностями JPA:
1. Первый с именем Entity
(не принимайте за аннотацию)
2. второй с именем Property
An Entity
может иметь 0..n экземпляров Property
. Код выглядит следующим образом:
@Entity
data class Entity (
@Id
@Column(name = "entity_id", updatable = false)
var entityId: String? = null,
@Column(nullable = true)
var type: String? = null
) {
@OneToMany(mappedBy = "entity")
var properties: List<Property>? = null
}
@Entity
data class Property (
@Id
@Column(name = "type")
var type: String? = null,
@Id
@ManyToOne
@JoinColumn(name = "entity_id")
private var entity: abc.model.Entity? = null
) : Serializable
Объявление составного первичного ключа как @EmbeddedId
следующим образом не решает проблему, поскольку Quarkus в настоящее время не допускает других аннотаций, кроме @Id
в данном случае:
@Entity
data class Entity (
@Id
@Column(name = "entity_id", updatable = false)
var entityId: String? = null,
@Column(nullable = true)
var type: String? = null
) {
@OneToMany(mappedBy = "propertyId.entityId")
var properties: List<Property>? = null
}
interface PropertyRepository : CrudRepository<Property, PropertyId>
@Embeddable
data class PropertyId (
var type: String? = null,
@Column(name = "entity_id")
private var entityId: String? = null
) : Serializable
@Entity
data class Property (
@EmbeddedId
var propertyId: PropertyId? = null,
@Column(name = "constant_value")
var constantValue: String? = null
)
java.lang.IllegalArgumentException: Currently only Entities with the @Id annotation are supported. Offending class is abc.model.Property
at io.quarkus.spring.data.deployment.generate.StockMethodsAdder.getIdAnnotationTargetRec(StockMethodsAdder.java:932)