我有我的实体类OneToMany
通过扩展创建定义的映射和Spring JPA库接口JpaRepository
春天的接口。
我已取为FetchType.LAZY
明确对中消协OneToMany
注解。
我面临的问题是,当我使用存储库中获得一个特定的记录,春天是获取其使用中定义的关联实体对象OneToMany
注释及其后续相关的实体对象等忽略了他们获取type.I我收到数额巨大的数据时,在Spring REST控制器使用它的网页。 几次,它也产生了异常的StackOverflow当它遇到圆形绑定。
我碰到的stackoverflow.com以下职位,但答案似乎不相关的现状..
春天JPA加载所有相关的属性,尽管在实体类将它们标记为FetchType.LAZY
更新
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class AbstractEntity implements Serializable {
/**
*
*/
private static final long serialVersionUID = -2700585394392789902L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@CreatedDate
private Date createdDate = new Date();
@LastModifiedDate
private Date lastModifiedDate = new Date();
@CreatedBy
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn
private User createdBy;
@LastModifiedBy
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn
private User lastModifiedBy;
@javax.persistence.Version
private long version;
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Date getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
@JsonIgnore
public User getCreatedBy() {
return createdBy;
}
public void setCreatedBy(User createdBy) {
this.createdBy = createdBy;
}
public void setLastModifiedBy(User lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
@Entity
@Table(name = "currencies")
public class Currency extends AbstractMasterEntity {
private static final long serialVersionUID = 1L;
@Override
public String toString() {
return "Currency [code=" + code + ", name=" + name + "]";
}
}