我们的映射超级类创建了byBy列,该列定义为延迟加载
DispatchQueue.main.async(execute: { () -> Void in
let image = UIImage(data: data!)
self.image = image
self.tableview.reloadData()
})
我需要在继承了上述类的子类之一中热切加载此属性。
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractAuditingEntity implements Serializable {
@CreatedBy
@ManyToOne(fetch = FetchType.LAZY)
@XmlTransient
@JoinColumn(name = "created_by", updatable = false, columnDefinition = "bigint")
protected User createdBy;
public User getCreatedBy() {
return createdBy;
}
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
我该怎么做?
我尝试了以下操作(使用了NamedEntityGraph和HQL),但是都没有从定义为延迟的MappedSuperClass返回createdBy
@Override
@XmlElement(name = "createdBy")
@JsonProperty("createdBy")
public User getCreatedBy() {
return super.getCreatedBy();
}
---使用HQL FETCH JOIN-
//defined at the top of Model
@NamedEntityGraphs({
// eagerly fetches created by and program names when used
@NamedEntityGraph(
name = "graphWithCreatedBy",
attributeNodes = {
@NamedAttributeNode("createdBy")
}
)
})
//Repository method
@EntityGraph(value = "Program.createdBy", type = EntityGraph.EntityGraphType.FETCH) //tried both LOAD and FETCH
Program findOne(Specification<Program> specification);
这两种方法均返回程序,但不能返回createdBy用户 我究竟做错了什么?