2013-10-14 59 views
1

我試圖根據公認的答案周圍添加Artcile的評論列表中的包裝類上Jersey/Jaxb aliasing a List of beansJAX-RS球衣號碼:@XmlElementWrapper返回

public class Article implements Serializable 
{ 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 
    ... 
    @ManyToMany(cascade = CascadeType.ALL) 
    @JoinTable(name = "ARTICLE_COMMENT", 
    joinColumns = 
    { 
     @JoinColumn(name = "ARTICLE_ID", referencedColumnName = "ID") 
    }, 
    inverseJoinColumns = 
    { 
     @JoinColumn(name = "COMMENT_ID", referencedColumnName = "ID") 
    }) 
    @XmlElementWrapper(name = "user_comments") 
    private List<Comment> comments; 

    public Article() 
    { 
    } 
... 
} 

而評論是

@XmlRootElement 
@Entity 
public class Comment implements Serializable 
{ 
    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 
    private String name; 

    /* 
    @ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER) 
    private Collection<Article> articles; 
    */ 
    ... 
} 

然而,它返回此錯誤

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions 
Klasse enthält zwei Eigenschaften mit demselben Namen "comments" 

更改收集到的評論列表不昌很多。任何人都知道我能做什麼?

+0

你的'Comment' bean看起來像什麼? – condit

回答

7

只是瘋狂的猜測 - 嘗試註釋getter而不是屬性。