【问题标题】:How to get a list of properties inside of entity in JPA and REST?如何在 JPA 和 REST 中获取实体内的属性列表?
【发布时间】:2013-08-29 22:07:05
【问题描述】:

环境

球衣 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 中获得城市?

我觉得有可能吗?

谢谢 萨米人

【问题讨论】:

  • 关系加载的默认设置是 LAZY。您是否填充了相关实体?

标签: jpa collections entity eclipselink jersey-2.0


【解决方案1】:
@XmlTransient---> **THIS OFF!**
public Collection<City> getCityCollection() {
        return cityCollection;
    }

@XmlTransient 关闭,我将其移至:

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

它正在工作:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-02
    • 2016-06-30
    • 2016-09-07
    • 2019-06-13
    • 1970-01-01
    • 2014-01-09
    • 2018-02-19
    • 2017-01-18
    相关资源
    最近更新 更多