我正在使用Micronaut Data JDBC遇到错误。我有此实体:
@MappedEntity(value = "document_metadata")
@AllArgsConstructor
@EqualsAndHashCode
public class DocumentMetadataJDBCEntity implements DocumentMetadata {
@Embeddable
@AllArgsConstructor
public static class MetadataPk {
@MappedProperty(value = "document_uid")
@NotNull
private UUID documentUid;
@MappedProperty(value = "metadata_key")
@NotNull
private String metadataKey;
public UUID getDocumentUid() {
return documentUid;
}
public String getMetadataKey() {
return metadataKey;
}
}
@EmbeddedId
private MetadataPk metadataPk;
@NotNull
private String metadataValue;
public MetadataPk getMetadataPk() {
return metadataPk;
}
@Override
public String getMetadataKey() {
return getMetadataPk().getMetadataKey();
}
@Override
public String getMetadataValue() {
return metadataValue;
}
public UUID getDocumentUid() {
return getMetadataPk().getDocumentUid();
}
}
插入时,我得到这个错误:
io.micronaut.data.exceptions.DataAccessException: SQL error executing INSERT: Batch entry 0 INSERT INTO "document_metadata" ("metadata_key","metadata_value","document_uid","document_uid","metadata_key") VALUES ('id','1234','c960d8de-99a4-40a6-91bf-b0d4a73910d6'::uuid,'c960d8de-99a4-40a6-91bf-b0d4a73910d6'::uuid,'id') was aborted: ERROR: column "document_uid" specified more than once
保存的代码是下一个:
Set<DocumentMetadataJDBCEntity> metadataSet = metadata.entrySet().stream()
.map(e -> new DocumentMetadataJDBCEntity(new DocumentMetadataJDBCEntity.MetadataPk(
savedDocument.getUid(), e.getKey()), e.getValue())).collect(toSet());
Iterable<DocumentMetadataJDBCEntity> persistedMetadata = documentMetadataJDBCRepository.saveAll(metadataSet);
你知道吗?
1条答案
按热度按时间n1bvdmb61#
将
@Transient
添加到您的方便访问器(getter)方法中:它“告诉”Micronaut不要将返回值保存到DB中。