A @OneToMany relationship with a Map loads the data only on the first call

Description

A @OneToMany relationship with a Map loads the data only on the first call when specifying FetchType.LAZY;

The first call for the map returns the Map with data;

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;

Environment

Hibernate 5.0.2.Final, on MySql (Google Cloud SQL)

Activity

Show:
Roland Beuker
December 13, 2016, 11:31 AM
Edited

I'm on a business trip at the moment, so there's no time for template code from my side.

The situation;

@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 to mExternalArticleStockLocationMap returns the database data, a second call returns an empty Map.
Could you create some test code Chris?

Chris Kohler
December 14, 2016, 10:33 PM

Sure i will give it a go.

Chris Cranford
May 18, 2017, 1:58 AM

It seems the map is annotated with @LazyCollection(LazyCollectionOption.EXTRA). Have you tried removing this annotation to see if the same problem occurs? Also I noticed you didn't include the HibernateEntity and IntermediateEntity super-types.

Roland Beuker
November 30, 2018, 9:01 AM

Hello Vlad,

In my first years with Hibernate 'collection mapping' seemed very important.
The most 'complex' issues were applied to/with Map's etc (as with this
issue).
In practice, however, it is much more convenient to keep things plain and
simple and handle search issues primary with queries.
Therefore my current projects only work with simple lists and sometimes a
set.

In summary, at this moment i don't have any code to reproduce this issue.
But i know the situation was just as specified in the description (the map
was empty on the second call).

I have to create a small project for tests like this.
How do you set up/create this small projects for your examples?
Do you have a template or the like?

Best regards,

Roland Beuker
Arcus Solutions
06-33974573

*
<https://nethunt.co/api/v1/track/link/click/5aeb5e401c3f279af11d3152/1543568080986/?link=http%3A%2F%2Farcus-solutions.nl%2F>*

Op vr 30 nov. 2018 om 09:10 schreef Vlad Mihalcea (JIRA) <

Vlad Mihalcea
December 3, 2018, 5:57 AM

You can use this template to replicate the issue.

Assignee

Unassigned

Reporter

Roland Beuker

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure