1

环境

泽西 Eclipselink (JPA)

实体

国家---城市

@OneToMany(cascade = CascadeType.ALL, mappedBy = "countryCountryId")
private Collection<City> cityCollection;

@XmlTransient
public Collection<City> getCityCollection() {
        return cityCollection;
    }

休息

@GET
@Override
@Produces({"application/xml", "application/json"})
public List<Country> findAll() {
    return super.findAll();
}

结果

<countries>
  <country>
   <country>Finland</country>
   <countryId>1</countryId>
   <lastUpdate>2013-08-30T00:43:35+03:00</lastUpdate>
  </country>
 <country>
  <country>Sweden</country>
  <countryId>2</countryId>
  <lastUpdate>2013-08-30T00:43:35+03:00</lastUpdate>
 </country>
</countries>

问题

为什么即使有领域也没有城市?

我怎样才能在同一个@GET 中获得城市?

有可能吗,我想是的?

谢谢萨米

4

1 回答 1

1
@XmlTransient---> **THIS OFF!**
public Collection<City> getCityCollection() {
        return cityCollection;
    }

@XmlTransient 关闭,我将其移至:

@XmlTransient
public Country getCountryCountryId() {
    return countryCountryId;
}

它正在工作:)

于 2013-08-30T15:01:44.253 回答