We're updating the issue view to help you get more done. 

Enhancement: Collection defined in @MappedSuperclass returns no result when loaded lazily

Description

When a collection is defined on a mappedsuperclass:

1 2 3 4 5 6 7 8 @MappedSuperclass public abstract class RelatedToEvents extends Base { protected Set<Event> events = new LinkedHashSet<>(); public void setEvents(Set<Event> events) { this.events = events; } }

extended by

1 2 3 4 5 6 7 8 9 10 11 12 @Entity @Inheritance(strategy = InheritanceType.JOINED) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class RequestWithEagerEvents extends RelatedToEvents { @ManyToMany(fetch = FetchType.EAGER) @Fetch(FetchMode.SELECT) public Set<Event> getEvents() { return events; } }

and

1 2 3 4 5 6 7 8 9 10 11 12 @Entity @Inheritance(strategy = InheritanceType.JOINED) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class RequestWithLazyEvents extends RelatedToEvents { @ManyToMany(fetch = FetchType.LAZY) @Fetch(FetchMode.SELECT) public Set<Event> getEvents() { return events; } }

Accessing the collection lazily after getting the entity from database returns no results, but results when loaded eagerly. When the collection property is moved outside the @MappedSuperclass or without bytecode enhancement, everything works.

Test case: https://github.com/nikowitt/hibernate-test-case-templates/tree/HHH-12601-eager-lazy-mappedsuperclass-collection

Environment

None

Status

Assignee

Unassigned

Reporter

Niko Wittenbeck

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.17
5.3.0.Final

Priority

Major