【发布时间】:2017-10-13 16:28:36
【问题描述】:
在我的 spring web-app 和 AJAX 后面调用以下异常:
com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: com.domain.entities.Person.followerd, could not initialize proxy - no Session
父实体:
@Entity
public class Person {
@OneToMany(mappedBy="follower")
@JsonIgnore
private List<FollowerPerson> followerd;
....
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name="phone", joinColumns=@JoinColumn(name="person"))
protected List<Phone> phones;
}
FollowerPerson 实体
@Entity
public class FollowerPerson implements Serializable {
@EmbeddedId
private FollowerPk id;
@MapsId("std")
@ManyToOne
private Person std;
@MapsId("follower")
@ManyToOne
private Person follower;
....
}
在我的 AppConfig 中,我使用这个 txManager spring + hibernate(基于 JPA):
@Bean
public PlatformTransactionManager txManager() {
JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(
getEntityManagerFactoryBean().getObject());
return jpaTransactionManager;
}
在查找所有人的 findAll dao 方法执行后,ajax 调用尝试识别列表时发生异常
当我用 fetch=FetchType.EAGER 注释这个属性时 会出现另一个异常:
cannot simultaneously fetch multiple bags: [com.domain.entities.Person.followerd, com.domain.entities.Person.phones]
请帮忙
【问题讨论】:
标签: ajax spring hibernate jackson sessionfactory