休息 - JPA:异常描述:在对象图

时间:2017-07-18 12:12:47

标签: json rest eclipselink moxy

我是每个人,

我使用JPA创建了一个RestFul服务来访问我的数据库。我用来检测错误et tomcat log给我:

javax.ws.rs.WebApplicationException: HTTP 500 Internal Server Error
    at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:865)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:243)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:230)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
    at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:103)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
    at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:88)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:149)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1139)
    at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:574)
    at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:381)
    at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:371)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:262)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1010)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:345)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:220)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[Exception [EclipseLink-25037] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A cycle is detected in the object graph.  This will cause an infinite loop: EJPlanning.Models.Planning@320a92e7 -> EJPlanning.Models.Groupe@d62730a -> EJPlanning.Models.Planning@320a92e7]
    at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:457)
    at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:863)
    ... 46 more
Caused by: Exception [EclipseLink-25037] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A cycle is detected in the object graph.  This will cause an infinite loop: EJPlanning.Models.Planning@320a92e7 -> EJPlanning.Models.Groupe@d62730a -> EJPlanning.Models.Planning@320a92e7
    at org.eclipse.persistence.exceptions.XMLMarshalException.objectCycleDetected(XMLMarshalException.java:401)
    at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:209)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
    at org.eclipse.persistence.internal.oxm.XMLCompositeCollectionMappingNodeValue.marshalSingleValue(XMLCompositeCollectionMappingNodeValue.java:334)
    at org.eclipse.persistence.internal.oxm.XMLCompositeCollectionMappingNodeValue.marshal(XMLCompositeCollectionMappingNodeValue.java:104)
    at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:149)
    at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102)
    at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59)
    at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:401)
    at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:240)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
    at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshalSingleValue(XMLCompositeObjectMappingNodeValue.java:260)
    at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshal(XMLCompositeObjectMappingNodeValue.java:151)
    at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102)
    at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59)
    at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:401)
    at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:240)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
    at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
    at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:751)
    at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:571)
    at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshalStreamOrWriter(XMLMarshaller.java:1107)
    at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:919)
    at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:862)
    at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:455)
    ... 47 more

经过多次搜索,我找不到可能的解决方案。所以我希望你能帮助我:

GROUPE:

    @Entity
@XmlRootElement
public class Groupe implements Serializable{
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    @Column(name = "GROUPE_ID")
    private int Id;

    private String Nom;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "Groupe")
    @JoinColumn(name="PLANNING_ID")
    private Collection<Planning> Plannings;

    @ManyToMany
    @JoinTable(name="GroupeActivite", 
            joinColumns=@JoinColumn(name="GROUPE_ID", referencedColumnName="GROUPE_ID"),
            inverseJoinColumns=@JoinColumn(name="ACTIVITE_ID", referencedColumnName="ACTIVITE_ID"))
    private Collection<Activite> Activites;

    public Groupe() {
    }


    public Groupe(String Nom, Collection<Planning> Plannings, Collection<Activite> Activites) {
        this.Nom = Nom;
        this.Plannings = Plannings;
        this.Activites = Activites;
    }

    public int getId() {
        return Id;
    }

    public void setId(int Id) {
        this.Id = Id;
    }

    public String getNom() {
        return Nom;
    }

    public void setNom(String Nom) {
        this.Nom = Nom;
    }

    public Collection<Planning> getPlannings() {
        return Plannings;
    }

    public void setPlannings(Collection<Planning> Plannings) {
        this.Plannings = Plannings;
    }

    public Collection<Activite> getActivites() {
        return Activites;
    }

    public void setActivites(Collection<Activite> Activites) {
        this.Activites = Activites;
    }

规划:

    @Entity
@XmlRootElement
public class Planning implements Serializable {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    @Column(name = "PLANNING_ID")
    private int Id;

    @Column(name="DATE_EVENEMENT")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateEvenement;

    private EnumTypePlanning Type; 

    @ManyToMany
    @JoinTable(name="ActivitePlanning", 
            joinColumns=@JoinColumn(name="PLANNING_ID", referencedColumnName="PLANNING_ID"),
            inverseJoinColumns=@JoinColumn(name="ACTIVITE_ID", referencedColumnName="ACTIVITE_ID"))
    private Collection<Activite> Activites;

    @ManyToOne(cascade = CascadeType.ALL) 
    @JoinColumn(name="GROUPE_ID", insertable = false, updatable = false)
    private Groupe Groupe;

    @ManyToMany
    @JoinTable(name="UtilisateurPlanning", 
            joinColumns=@JoinColumn(name="PLANNING_ID", referencedColumnName="PLANNING_ID"),
            inverseJoinColumns=@JoinColumn(name="UTILISATEUR_ID", referencedColumnName="UTILISATEUR_ID"))
    private Collection<Utilisateur> Moniteurs;

    public Planning(){

    }

    public Planning(Date dateEvenement, EnumTypePlanning Type, Collection<Activite> Activite, Groupe Groupe){
        this.dateEvenement = dateEvenement;
        this.Type=Type;
        this.Activites=Activite;
        this.Groupe=Groupe;

    }

    public int getId() {
        return Id;
    }

    public void setId(int Id) {
        this.Id = Id;
    }

    public Date getDateEvenement() {
        return dateEvenement;
    }

    public void setDateEvenement(Date dateEvenement) {
        this.dateEvenement = dateEvenement;
    }

    public EnumTypePlanning getType() {
        return Type;
    }

    public void setType(EnumTypePlanning Type) {
        this.Type = Type;
    }

    public Collection<Activite> getActivites() {
        return Activites;
    }

    public void setActivites(Collection<Activite> Activites) {
        this.Activites = Activites;
    }

    public Groupe getGroupe() {
        return Groupe;
    }

    public void setGroupe(Groupe Groupe) {
        this.Groupe = Groupe;
    }



    public Collection<Utilisateur> getMoniteurs() {
        return Moniteurs;
    }

    public void setMoniteurs(Collection<Utilisateur> Moniteurs) {
        this.Moniteurs = Moniteurs;
    }

GroupeMapper:

public class GroupeMapper extends AbstractFacade  implements IGroupeMapper{

   @PersistenceContext(unitName = "EJPlanningRestPU")
    private EntityManager em;
    private List<Groupe> list;

    public GroupeMapper() {
        super(Groupe.class);
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("EJPlanningRestPU");
        em = emf.createEntityManager();       }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public void getAll() {
    super.findAll();
    }

PlanningMapper:

public class PlanningMapper extends AbstractFacade  implements IPlanningMapper{


    @PersistenceContext(unitName = "EJPlanningRestPU")
    private EntityManager em;
    private List<Planning> list;

    public PlanningMapper() {
        super(Planning.class);
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("EJPlanningRestPU");
        em = emf.createEntityManager();       }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    public void getAll() {
    super.findAll();
    }

我希望你能帮助我,我从1周开始就在寻找这个解决方案,找到解决方案对我来说非常重要。

0 个答案:

没有答案