尽管使用JsonIgnore,但未能在ManyToMany关系中懒散地初始化角色集合 [英] failed to lazily initialize a collection of role in ManyToMany relationship despite using JsonIgnore

查看:119
本文介绍了尽管使用JsonIgnore,但未能在ManyToMany关系中懒散地初始化角色集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个业务对象有很多关系。我正在使用REST服务调用下面给出的DAO方法,并获得政治事件的政治指标列表。然而,虽然DAO中的piList成功给了我政治指标列表,但它仍然给我一个例外

无法懒惰地初始化一个角色集合...



通过引用链:

  org.hibernate.collection.internal.PersistentBag [0] -----> PolIndicator.piList.role 
org.jboss.resteasy.spi.writerException
org.codehaus.jackson。 map.JsonmappingException

我已经使用了 @JsonIgnore 在政治指标类中反对政治事件属性,但仍会发生懒惰异常。



我在哪里出错?

  PolEvent {

@Id
@Column(name =SEQ_EVENT_ID)
私人BigDecimal ID;

@Column(name =EVENT_NAME)
private String eventName;

@ManyToMany
@JoinTable(
name =POL_LINK_INDCTR
joinColumns = {@ JoinCo lumn(name =SEQ_EVENT_ID)},
inverseJoinColumns = @ JoinColumn(name =SEQ_PI_ID)

private List< PolIndicator> piList;



PolIndicator {

@Id
@Column(name =SEQ_PI_ID)
private BigDecimal id;

@Column(name =POL_IND_NAME)
private String piName;

@ManyToMany(mappedBy =piList)
@JsonIgnore
private List< PolEvent>活动列表;

$ / code>

DAO Layer代码

  public List< PolIndicator> getPiList(String eventId){

Criteria criteria = session.createCriteria(PolEvent.class);
criteria.add(Restrictions.eq(id,id);
PolEvent polEvent = new PolEvent();
polEvent = criteria.uniqueResult();
piList = polEvent .getPiList();
return piList();
}


解决方案

您需要将注释移至getter方法:

  @JsonIgnore 
public List< PolEvent> getEventList(){
return eventList;
}


I have two business objects having many too many relationships. I am using a REST service to call the DAO method given below and get a list of political indicators for a political event. However though the piList in DAO successfully gives me the list of Political Indicators but it still gives me an exception

Failed to lazily intialize a collection of role...

through reference chain:

org.hibernate.collection.internal.PersistentBag[0]----->PolIndicator.piList.role
org.jboss.resteasy.spi.writerException
org.codehaus.jackson.map.JsonmappingException"

I have used @JsonIgnore in the Political Indicator class against the political event property but still the lazy exception happens.

Where am I going wrong?

PolEvent {

    @Id
    @Column(name="SEQ_EVENT_ID")
    private BigDecimal id;

    @Column(name="EVENT_NAME")
    private String eventName;

    @ManyToMany
    @JoinTable(
        name="POL_LINK_INDCTR"
        joinColumns={@JoinColumn(name="SEQ_EVENT_ID")},
        inverseJoinColumns=@JoinColumn(name="SEQ_PI_ID")
    )
    private List <PolIndicator> piList;
}


PolIndicator {

    @Id
    @Column(name="SEQ_PI_ID")
    private BigDecimal id;

    @Column(name="POL_IND_NAME")
    private String piName;

    @ManyToMany(mappedBy="piList")
    @JsonIgnore
    private List <PolEvent> eventList; 
}

DAO Layer Code

public List <PolIndicator> getPiList (String eventId) {

    Criteria criteria = session.createCriteria(PolEvent.class);
    criteria.add(Restrictions.eq("id",id);
    PolEvent polEvent = new PolEvent();
    polEvent=criteria.uniqueResult();
    piList = polEvent.getPiList();
    return piList();
}

解决方案

You need to move the annotation to the getter method:

@JsonIgnore
public List <PolEvent> getEventList() {
    return eventList;
}

这篇关于尽管使用JsonIgnore,但未能在ManyToMany关系中懒散地初始化角色集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆