【发布时间】:2020-06-30 18:45:59
【问题描述】:
我有一些实体AuditEntity。我需要通过entityId 获取eventType 值。
在执行 findFirstByEntityIdOrderByCreatedTimeDesc 方法时,如何使 AuditEntity 中的 dealState 字段始终为零,而不考虑数据库中该字段的值?
如果dealState 字段不是另一个表的键,那么使用@Lazy (import org.springframework.context.annotation.Lazy) 是否正确?
@Entity
@Table(name = "audit")
class AuditEntity(
@Id
override var id: Long? = null,
@Basic
@Column(name = "entity_id")
val entityId: Long,
@Basic
@Enumerated(EnumType.STRING)
@Column(name = "event_type")
val eventType: AuditEventType,
@Type(type = "jsonb")
@Column(name = "deal_state", columnDefinition = "jsonb")
val dealState: Deal? = null
) : BaseEntity<Long>()
@Repository
interface AuditRepository : JpaRepository<AuditEntity, Long> {
fun findFirstByEntityIdOrderByCreatedTimeDesc(entityId: Long): AuditEntity?
}
【问题讨论】:
标签: spring kotlin spring-data-jpa spring-data lazy-loading