简体   繁体   中英

Wildfly 16, the anotation @JsonIgnore doesn't work

I use wildfly 1-, and I implement a web service rest.

@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
}

When I want to call the méthod lireTousPromotion(), I have the exception :

Exception handling request to
/7EtudiantPromotionPresentationTout/rest/promotions:
org.jboss.resteasy.spi.UnhandledException:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: entite.Promotion.modules, could not initialize proxy - no Session

I don't know how I can don't srialyse the modules fields. The @JsonIgnore doesn't be set.
See you

Try using javax.xml.bind.annotation.XmlTransient annotation for Promotion#modules field.

More information: http://blog.bdoughan.com/2012/04/jaxb-and-unmapped-properties.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM