【发布时间】:2021-01-22 19:01:25
【问题描述】:
我有两个具有一对多关系的表。铅和铅活动。一个潜在客户可以有多个活动。
问题陈述 - 我想在潜在客户表中增加一列来了解任何潜在客户的最后修改日期。上次修改日期将是上次创建或更新活动的日期。所以,我使用@Formula 来获取列。但是,我无法获得正确的日期,而是获得字段 lastModifiedDate 的空值。任何人都可以帮助我哪里出错。下面是表结构
@Entity
@Table(name = "customer_lead")
@Where(clause = ReusableFields.SOFT_DELETED_CLAUSE)
@Audited(withModifiedFlag = true)
@Data
public class Lead extends ReusableFields implements Serializable
{
//other fields
@NotAudited
@Formula("(Select max(modified) from lead_activity la Where la.lead_id=lead_id)")
Date lastModifiedDate;
}
领导活动
@Entity
@Table(name = "LeadActivity")
@Data
@Where(clause = ReusableFields.SOFT_DELETED_CLAUSE)
public class LeadActivity extends ReusableFields implements Serializable
{
// other fields
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "lead_id", nullable = false)
@JsonIgnoreProperties(
{ "hibernateLazyInitializer", "handler" })
@NotFound(action = NotFoundAction.IGNORE)
Lead lead;
}
修改字段的映射超类
@MappedSuperclass
@Audited
public class ReusableFields implements Serializable
{
public static final String SOFT_DELETED_CLAUSE = "is_deleted = 'false'";
@Column(name="is_deleted", columnDefinition="BOOLEAN DEFAULT true")
public boolean isDeleted;
@CreationTimestamp
@Column(name = "created_at")
@JsonProperty("created")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss ")
private Date created;
@Column(name = "updated_at")
@JsonProperty("updated")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
@UpdateTimestamp
private Date modified;
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean isDeleted) {
this.isDeleted = isDeleted;
}
public static String getSoftDeletedClause() {
return SOFT_DELETED_CLAUSE;
}
}
【问题讨论】:
标签: spring spring-boot hibernate spring-data-jpa spring-data