2013-08-29 40 views
1

环境如何获得JPA和REST中实体的属性列表?

新泽西 的EclipseLink(JPA)

实体

国家---城市

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

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

REST

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

这是否可能,我认为呢?

感谢 萨米

+0

默认设置是懒惰。你有没有填充你的相关实体? – gerrytan

回答

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

@XmlTransient了,我把它移到:

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

而且这是工作关系装载:)