Failed to lazily initialize role collection in ManyToMany relationship despite using JsonIgnore
I have two business objects that have too many relationships. I am using a REST service to call the DAO method below and get a list of political indicators for a political event. However, while piList in DAO successfully gives me a list of political indicators, it still gives me an exception.
Failed to lazily intialize a collection of role...
via link chain:
org.hibernate.collection.internal.PersistentBag[0]----->PolIndicator.piList.role
org.jboss.resteasy.spi.writerException
org.codehaus.jackson.map.JsonmappingException"
I used @JsonIgnore
in class "Political Indicator" against the property of a political event, but there is still a lazy exception.
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 level 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();
}
+1
source to share