A @OneToMany relationship with a Map loads the data only on the first call when specifying FetchType.LAZY;
@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "mStockLocation") @MapKeyJoinColumn(name="EXTERNALARTICLE_ID") private Map<ExternalArticle, ExternalArticleStockLocation> mExternalArticleStockLocationMap = new LinkedHashMap();
The first call for the map returns the Map with data;
public Map<ExternalArticle, ExternalArticleStockLocation> getExternalArticleStockLocationMap() { return mExternalArticleStockLocationMap; }
The second call returns an empty HashMap. The problem 'disappears' when i switch to FetchType.EAGER or when i save the HashMap at the call;
public Map<ExternalArticle, ExternalArticleStockLocation> getExternalArticleStockLocationMap() { // Bug fix! setExternalArticleStockLocationMap(mExternalArticleStockLocationMap);
return mExternalArticleStockLocationMap; }
public void setExternalArticleStockLocationMap(Map<ExternalArticle, ExternalArticleStockLocation> pExternalArticleStockLocationMap) { mExternalArticleStockLocationMap = pExternalArticleStockLocationMap; } |
|