关于webshpehre liberty和jax-rs 2.0的JPA数据撤销问题

时间:2016-12-04 18:55:10

标签: jpa jax-rs websphere-liberty

这是我的实体类

    @Entity
@Table( name = "NEO_TEAM",  schema = "METRICS" )
public class ETeam implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    private int id;

    @Column(name="NAME")
    private String name;

    @Column(name="DESCRIPTION")
    private String description;

    //bi-directional many-to-one association to ETeamQueue
    @OneToMany(mappedBy="eteam"  , fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)

    private List<ETeamQueue> teamQueue;

    public ETeam(int id,String name,String description){
        this.id = id;
        this.name = name;
        this.description = description;
    }
    public ETeam(String name,String description){
        this.name = name;
        this.description = description;
    }
    public ETeam() {
    }

    public int getId() {
        return this.id;
    }

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

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<ETeamQueue> getTeamQueue() {
        return this.teamQueue;
    }

    public void setTeamQueue(List<ETeamQueue> teamQueue) {
        this.teamQueue = teamQueue;
    }

    public ETeamQueue addTeamQueue(ETeamQueue teamQueue) {
        getTeamQueue().add(teamQueue);
        teamQueue.setEteam(this);

        return teamQueue;
    }

    public ETeamQueue removeTeamQueue(ETeamQueue teamQueue) {
        getTeamQueue().remove(teamQueue);
        teamQueue.setEteam(null);

        return teamQueue;
    }


}

我的REST调用和JPQL查询

@Path("team")
@Produces(MediaType.APPLICATION_JSON)
public class TeamResource {
    TeamService ts = new TeamService();
    @GET
    @Path("/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public List<ETeam> listTeam(@PathParam("id") int id){

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("NeoMetrics");
        EntityManager em = emf.createEntityManager();

        Query query = em.createQuery("select e from ETeam e   where e.id = :id ",ETeam.class);
        query.setParameter("id", id);
        List<ETeam> lis = (List<ETeam>) query.getResultList();

        //List<ETeam> lis = ts.getTeam(id);

        return lis;
    }

我想从团队表中只获取一条记录,但是它给我的结果如图所示,显示结果被循环了数千次,其非常长的输出结果我只放了一部分,任何帮助都会真的赞赏

Rest call out put

0 个答案:

没有答案