-1

我有三个表( People、Group、person_group ),我想获取特定组的人,所以我使用了

selectedGroup.getPeopleCollection();

这是我的实体类:

  @Entity
@Table(name = "group_u")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "GroupU.findAll", query = "SELECT g FROM GroupU g"),
    @NamedQuery(name = "GroupU.findById", query = "SELECT g FROM GroupU g WHERE g.id = :id"),
    @NamedQuery(name = "GroupU.findByName", query = "SELECT g FROM GroupU g WHERE g.name = :name")})
public class GroupU implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID")
    private Integer id;
    @Size(max = 50)
    @Column(name = "Name")
    private String name;
    @JoinTable(name = "person_group", joinColumns = {
        @JoinColumn(name = "GroupID", referencedColumnName = "ID")}, inverseJoinColumns = {
        @JoinColumn(name = "PerID", referencedColumnName = "ID")})
    @ManyToMany
    private Collection<People> peopleCollection;

    public GroupU() {
    }

    public GroupU(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

    @XmlTransient
    @JsonIgnore
    public Collection<People> getPeopleCollection() {
        return peopleCollection;
    }

    public void setPeopleCollection(Collection<People> peopleCollection) {
        this.peopleCollection = peopleCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GroupU)) {
            return false;
        }
        GroupU other = (GroupU) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entities.GroupU[ id=" + id + " ]";
    }

}

当我打电话时,selectedGroup.getPeopleCollection();我总是得到空值,注意:我使用 netbeans 来生成我的实体类。

4

1 回答 1

0
    @XmlTransient
    @JsonIgnore
    public Collection<People> getPeopleCollection() {
        return peopleCollection;
    }

我从上面的代码中删除了这两行,问题就解决了。

  @XmlTransient
  @JsonIgnore
于 2013-06-07T12:07:05.113 回答