我正在 javaEE6 中开发我的第一个 RestFul webServices。这是我的实体 Bean
@XmlRootElement
@Entity
public class MyEntity implements Serializable {
@Id
@GeneratedValue
private long idEntity;
private String name;
private String description;
@OneToMany(mappedBy = "entity" , fetch = FetchType.EAGER)
private List<EntityB> list;
//Get and set
}
@Entity
public class EntityB {
@Id
@GeneratedValue
private long idCategoria;
@ManyToOne
private MyEntity myEntity;
}
这是我的网络服务
@Path("myentity")
@Produces( {MediaType.APPLICATION_XML , MediaType.APPLICATION_JSON })
@Consumes( {MediaType.APPLICATION_XML , MediaType.APPLICATION_JSON })
@Stateless
public class MyEntityService {
@Inject
MyEntityDao entityDao;
@GET
@Path("{id}/")
public MyEntity findById(@PathParam("id") Long id){
return entityDao.findById(id);
}
}
最后我配置了泽西岛
@ApplicationPath("ws")
public class ApplicationConfig extends Application {
}
现在,如果我尝试调用我的 Web 服务(localhost:8080/xxxx/ws/myentity),我会收到此错误:
HTTP 状态 500 - javax.xml.bind.MarshalException - 带有链接异常:[com.sun.istack.SAXException2:在对象图中检测到循环。这将导致无限深的 XML