【发布时间】:2020-07-03 01:55:33
【问题描述】:
我使用wildfly 1-,并实现了一个Web 服务休息。
@Entity
@XmlRootElement
public class Promotion implements Serializable {
@Id
private String acronyme;
private String intitule;
@OneToMany(fetch = FetchType.EAGER)
private List<Etudiant> etudiants = new ArrayList<>();
@OneToMany
private List<Module> modules;
public Promotion() {}
public Promotion(String titre,String acronyme) {
this.intitule = titre;
this.acronyme = acronyme;
etudiants = new ArrayList<Etudiant>();
}
.......... etc
}
@Path(value="/promotions")
public class RestServicePromotion {
@Inject
private MetierItf metier;
@GET
@Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
public List<Promotion> lireTousPromotion() {
System.out.println(metier.lireTousPromotion());
return metier.lireTousPromotion();
}
.... etc
}
当我想调用方法 lireTousPromotion() 时,我遇到了异常:
异常处理请求
/7EtudiantPromotionPresentationTout/rest/promotions:
org.jboss.resteasy.spi.UnhandledException:
org.hibernate.LazyInitializationException:未能延迟初始化角色集合:entite.Promotion.modules,无法初始化代理 - 没有会话
我不知道我怎么能不srialyse 模块字段。未设置 @JsonIgnore。
再见
【问题讨论】: