2017-10-13 86 views
0

我在春天web應用程序和AJAX背後叫下面的異常火災:傑克遜例外/休眠web應用

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", [email protected](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彈簧+冬眠(JPA爲主):

@Bean 
public PlatformTransactionManager txManager() { 
    JpaTransactionManager jpaTransactionManager = new JpaTransactionManager(
      getEntityManagerFactoryBean().getObject()); 
    return jpaTransactionManager; 
} 

當Ajax調用試圖識別的findAll DAO方法執行後的名單,看起來所有人

當我與註釋取指令= FetchType.EAGER 的其他異常,而不是會出現這個屬性的例外發生:

cannot simultaneously fetch multiple bags: [com.domain.entities.Person.followerd, com.domain.entities.Person.phones] 

請幫助

回答

1

更改列表設置,如果你能。 LinkedHashSet如果您仍然需要訂單。