A @OneToMany relationship with a Map loads the data only on the first call when specifying FetchType.LAZY; {code} @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "mStockLocation") @MapKeyJoinColumn(name="EXTERNALARTICLE_ID") private Map<ExternalArticle, ExternalArticleStockLocation> mExternalArticleStockLocationMap = new LinkedHashMap(); {code} The first call for the map returns the Map with data; {code} public Map<ExternalArticle, ExternalArticleStockLocation> getExternalArticleStockLocationMap() { return mExternalArticleStockLocationMap; } {code} 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; {code} public Map<ExternalArticle, ExternalArticleStockLocation> getExternalArticleStockLocationMap() { // Bug fix! setExternalArticleStockLocationMap(mExternalArticleStockLocationMap); return mExternalArticleStockLocationMap; } {code} |
|