【问题标题】:Jackson exception after Ajax call in Spring/hibernate web-app在 Spring/hibernate web-app 中 Ajax 调用后的 Jackson 异常
【发布时间】: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


    【解决方案1】:

    如果可以,请更改要设置的列表。 LinkedHashSet 如果您仍然需要订单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2020-10-10
      • 2019-05-03
      • 1970-01-01
      • 2014-07-27
      • 2016-11-11
      • 2021-03-02
      相关资源
      最近更新 更多