0
我正在javaEE6中開發我的firt RestFul web服務。 這是我的實體Bean我的第一個RESTful Web服務出現問題
@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;
}
這是我的WebServices
@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服務(本地主機:8080/xxxx/ws/myentity)我得到這個錯誤:
HTTP狀態500 - javax.xml.bind.M arshalException - 帶有鏈接的異常:[com.sun.istack.SAXException2:在對象圖中檢測到一個循環。這將導致無限深的XML