如何使用Quarkus JPA声明组合键?
在Quarkus的.as-console-wrapper { max-height: 100% !important; top: 0; }
类中尝试使用多个@Id
注释会导致错误:
@Entity
但是首先,在声明
之后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>>
实例的可能性。
如何避免此错误?
我正在处理两个JPA实体:
1.第一个名为Property
(请不要误解注释)
2.第二个名为Entity
Property
可以有{。{1}}的0..n个实例。代码如下:
Entity
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
}
并不能解决问题,因为在这种情况下Quarkus当前不允许使用@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
@Id
答案 0 :(得分:2)
有可能,您的实体必须扩展PanacheEntityBase并使用类级别的注释@ Table,@ Entity,@ IdClass(PK.class),其中Pk是具有复合主键字段的POJO,然后您必须声明实体中带有@Id注释的相同字段。例如:
@Entity()
@Table(name = "agent")
@IdClass(AgentPK.class)
public class AgentBRA extends PanacheEntityBase {
@Id
public Integer idUsuario;
@Id
public Integer idAgent;
和AgentPk:
public class AgentPK implements Serializable{
protected Integer idUsuario;
protected Integer idAgent;
// getters setters and hascode and equals methods